Search Header Logo

TECH TITAN

Authored by Praveen Mishra

Used 2+ times

TECH TITAN
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

25 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following loops is used for definite iteration?

a) while loop

b) for loop

c) repeat loop

d) if loop

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is the key difference between a "while" loop and a "for" loop in Python?

"for" loops can have a condition, while "while" loops cannot.

"while" loops are used for counting, while "for" loops are used for indefinite iterations.

"for" loops can only iterate over lists, while "while" loops can iterate over any data type.

"for" loops specify the iteration variable explicitly, while "while" loops do not.

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What will be the output of the following code?

x = 5

while x > 0:

print(x)

x -= 1

else:

print("Loop finished.")

5 4 3 2 1

5 4 3 2 1 Loop finished.

1 2 3 4 5

Loop finished.

4.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is the output of the following code?

for i in range(1,6+1):

print(i)

1234567

1234567+1

7654321+1

123456

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

How can you prevent an infinite loop in Python?

By using the "break" statement.

By ensuring the loop condition becomes False at some point.

By using the "continue" statement.

By using the "pass" statement.

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

x = 5

while x > 0:

x -= 1

print(x)

What will be the output of the code snippet above?

5

4

1

0

7.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following code snippets will correctly print all the even numbers from 2 to 10 using a loop in Python?

for i in range(2, 11):

if i % 2 == 0:

print(i)

num = 2

while num <= 10:

if num % 2 == 0:

print(num)

num += 2

for i in range(2, 11, 2):

print(i)

num = 2

while num < 10:

if num % 2 == 0:

print(num)

num += 1

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?