Search Header Logo

Mastering Python Loops Quiz

Authored by Shilpa M

Other

12th Grade

Used 2+ times

Mastering Python Loops Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the primary purpose of a for loop in Python?

To execute a block of code a specific number of times

To execute a block of code while a condition is true

To execute a block of code indefinitely

To execute a block of code based on user input

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a correct syntax for a while loop in Python?

`while x > 0 { print(x) }`

`while (x > 0): print(x)`

`while x > 0: print(x)`

`while x > 0 do print(x)`

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code snippet? ```python for i in range(3): print(i) ```

0 1 2

1 2 3

0 1 2 3

1 2

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In Python, what keyword is used to exit a loop prematurely?

exit

stop

break

quit

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code? ```python x = 0 while x < 3: x += 1 print(x) ```

0

1

2

3

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following statements is true about nested loops?

Nested loops are not allowed in Python

A nested loop is a loop inside another loop

Nested loops can only be used with for loops

Nested loops must have the same number of iterations

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code? ```python for i in range(2): for j in range(2): print(i, j) ```

0 0 0 1 1 0 1 1

0 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0

0 0 0 1 1 0 1 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?