Font size
WorksheetsPython Code Quiz
Total questions: 11
Worksheet time: 6mins
Which of the following data object/structures are iterables?
Number
String
List
Char
What does the following code print?
my_iterable = [1, 2, 3]
for item_name in my_iterable :
- print(my_iterable[item_name - 1])
Error
3,2,1
1,2,3
1,2
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)
All even numbers
All odd numbers
All the numbers
None
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)
-55
0
-5
55
mystring = "hello"
for letter in mystring :
- print(mystring.find(letter))
0,1,2,2,4
0,1,2,3,4
0,1,1,2,4
0,1,2,3,3
What will the following code output?
myTuple = [(1, 2), (3, 4), (5, 6)]
for (a, b) in myTuple :
- print(a + b)
1,2,3,4,5,6
1,3,5
2,4,6
3,7,11
x = 0
while x < 5:
- print(f'The current value of x is {x}')
-- x = x + 2
2,4
2,4,6
0,2,4
0,2,4,6
x = 0;
while x + 1 < 2
- print(x)
- x = x + 1
Infinite Loop
0
1
0,1
x = 0
while x + 1 < 5:
- x = x + 1
else:
- x += 1
print(x)
4
6
5
Infinite Loop
for letter in "12345":
- if letter == 3:
-- continue
- print(letter)
1,2,4,5
1,2,3,4,5
2,3,4,5
Error
for letter in "12345":
- if letter == 3:
-- break
- print(letter)
1,2,4,5
1,2
1,2,3,4,5
Error
