Python Loop Quiz

Python Loop Quiz

12th Grade

20 Qs

quiz-placeholder

Similar activities

Python Function Structure

Python Function Structure

8th - 12th Grade

19 Qs

Python Programming

Python Programming

3rd Grade - University

17 Qs

EME316 Quiz 02

EME316 Quiz 02

10th Grade - University

15 Qs

FTC Simulator JAVA Block Programming Movement & Sensors

FTC Simulator JAVA Block Programming Movement & Sensors

9th - 12th Grade

20 Qs

Programming Fundamentals

Programming Fundamentals

KG - University

20 Qs

Engineering First Semester

Engineering First Semester

9th Grade - University

15 Qs

Season 1 #Spaic Python Weekly Quiz

Season 1 #Spaic Python Weekly Quiz

KG - Professional Development

20 Qs

Python - Selection (IF statements)

Python - Selection (IF statements)

9th - 12th Grade

17 Qs

Python Loop Quiz

Python Loop Quiz

Assessment

Quiz

Other

12th Grade

Hard

Created by

ruth sutton

Used 1+ times

FREE Resource

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a for loop used for in Python?

To execute a block of code indefinitely

To iterate over a sequence

To evaluate conditions only

To terminate a program

Answer explanation

A for loop in Python is specifically designed to iterate over a sequence, such as a list, tuple, or string, allowing you to execute a block of code for each item in that sequence.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code? python Copy code for i in range(3): print(i)

1 2 3

0 1 2

0 1 2 3

None

Answer explanation

The code uses a for loop with range(3), which generates numbers starting from 0 up to, but not including, 3. Therefore, the output will be 0, 1, and 2, making the correct answer '0 1 2'.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What keyword is used to stop a while loop in Python?

exit

stop

break

continue

Answer explanation

In Python, the keyword 'break' is used to exit a while loop prematurely. The other options, 'exit', 'stop', and 'continue', do not serve this purpose. 'Continue' actually skips to the next iteration of the loop.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How many times will this loop run? python Copy code count = 0 while count < 5: count += 1

4

5

Infinite

6

Answer explanation

The loop starts with count = 0 and increments count by 1 each iteration. It runs while count is less than 5. Therefore, it will run 5 times (count = 1 to 5) before exiting, making the correct answer 5.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does range(5) generate?

1 to 5

0 to 5

0 to 4

Infinite values

Answer explanation

The function range(5) generates a sequence of numbers starting from 0 up to, but not including, 5. Therefore, it produces the values 0, 1, 2, 3, and 4, making the correct answer 0 to 4.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the continue keyword do in a loop?

Stops the loop completely

Skips the current iteration and continues to the next

Repeats the current iteration

Breaks the loop

Answer explanation

The continue keyword in a loop skips the current iteration when encountered and proceeds to the next iteration. This allows the loop to continue running without executing the remaining code in the current iteration.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will this code output? python Copy code for i in range(4): if i == 2: continue print(i)

0 1 2 3

0 1 3

1 3

None

Answer explanation

The loop iterates from 0 to 3. When i is 2, the 'continue' statement skips the print. Thus, the output is 0, 1, and 3, making the correct answer '0 1 3'.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?