wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Code Quiz

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

Which of the following data object/structures are iterables?

a)

Number

b)

String

c)

List

d)

Char

2.

What does the following code print?

my_iterable = [1, 2, 3]

for item_name in my_iterable :

- print(my_iterable[item_name - 1])

a)

Error

b)

3,2,1

c)

1,2,3

d)

1,2

3.

What will the following code output?

my_list = [1,2,3,4,5,6,7,8,9,10]

for each_item in my_list:

- if each_item % 2 != 0:

-- print(each_item)

a)

All even numbers

b)

All odd numbers

c)

All the numbers

d)

None

4.

What will the code output?

subtract = 0

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for each_item in my_list:

- subtract += each_item

-- print(subtract)

a)

-55

b)

0

c)

-5

d)

55

5.

mystring = "hello"

for letter in mystring :

- print(mystring.find(letter))

a)

0,1,2,2,4

b)

0,1,2,3,4

c)

0,1,1,2,4

d)

0,1,2,3,3

6.

What will the following code output?

myTuple = [(1, 2), (3, 4), (5, 6)]

for (a, b) in myTuple :

- print(a + b)

a)

1,2,3,4,5,6

b)

1,3,5

c)

2,4,6

d)

3,7,11

7.

x = 0

while x < 5:

- print(f'The current value of x is {x}')

-- x = x + 2

a)

2,4

b)

2,4,6

c)

0,2,4

d)

0,2,4,6

8.

x = 0;

while x + 1 < 2

- print(x)

- x = x + 1

a)

Infinite Loop

b)

0

c)

1

d)

0,1

9.

x = 0

while x + 1 < 5:

- x = x + 1

else:

- x += 1

print(x)

a)

4

b)

6

c)

5

d)

Infinite Loop

10.

for letter in "12345":

- if letter == 3:

-- continue

- print(letter)

a)

1,2,4,5

b)

1,2,3,4,5

c)

2,3,4,5

d)

Error

11.

for letter in "12345":

- if letter == 3:

-- break

- print(letter)

a)

1,2,4,5

b)

1,2

c)

1,2,3,4,5

d)

Error