Python For Loops Quiz

Python For Loops Quiz

12th Grade

12 Qs

quiz-placeholder

Similar activities

Trace Tables

Trace Tables

12th Grade

17 Qs

Computer Science 2: Control Structures

Computer Science 2: Control Structures

8th - 12th Grade

11 Qs

GCSE Computer Science - Programming Keywords

GCSE Computer Science - Programming Keywords

9th - 12th Grade

15 Qs

Loops

Loops

9th - 12th Grade

10 Qs

Recursion in Java

Recursion in Java

11th - 12th Grade

15 Qs

1.1.5 CSE Iteration and Loops

1.1.5 CSE Iteration and Loops

9th - 12th Grade

14 Qs

CodeHS 2.10 While Loops

CodeHS 2.10 While Loops

9th - 12th Grade

10 Qs

Code.org Unit 5 - Loops

Code.org Unit 5 - Loops

9th - 12th Grade

10 Qs

Python For Loops Quiz

Python For Loops Quiz

Assessment

Quiz

Computers

12th Grade

Medium

Created by

Nicol Sutherland

Used 2+ times

FREE Resource

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a for loop used for in Python?

Iterating over a sequence

Defining a function

Creating a class

Handling exceptions

Answer explanation

A for loop in Python is used for iterating over a sequence, making it the correct choice among the options provided.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is NOT a sequence that a for loop can iterate over?

Integer

Dictionary

Tuple

List

Answer explanation

The correct choice is Integer because a for loop cannot directly iterate over a single integer value, it needs to be part of a sequence like a list, tuple, or dictionary.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the break statement do in a for loop?

Skips the current iteration

Continues with the next iteration

Stops the loop before it has looped through all the items

Restarts the loop

Answer explanation

Stops the loop before it has looped through all the items

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the continue statement do in a for loop?

Exits the loop

Skips the current iteration and continues with the next

Stops the loop

Restarts the loop

Answer explanation

Skips the current iteration and continues with the next

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the range() function do?

Returns a sequence of numbers

Returns a list of strings

Returns a dictionary

Returns a set of tuples

Answer explanation

The range() function returns a sequence of numbers, allowing you to generate a series of integers within a specified range.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code? for x in range(2, 6): print(x)

2 3 4 5 6

2 3 4 5

0 1 2 3 4 5

3 4 5 6

Answer explanation

The output will be 2 3 4 5 because the range function generates numbers from 2 to 5 (not including 6) and the loop prints each number in the range.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of the else block in a for loop?

To execute a block of code if the loop is infinite

To execute a block of code if the loop is skipped

To execute a block of code before the loop starts

To execute a block of code when the loop is finished

Answer explanation

To execute a block of code when the loop is finished

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?