WorksheetsIntro to Programming Quiz 2
Total questions: 10
Worksheet time: 5mins
Which of the following methods adds an element to the end of a list?
What does the following code return?
my_list = [10, 20, 30, 40, 50]
print(my_list[1:4])
What will be the output of the following code?
t = {'a': 1, 'b': 2, 'c': 3}
print(t['b'])
Key Error
3
How can you add a new key-value pair to a dictionary?
a) my_dict.add('d', 4)
b) my_dict['d'] = 4
c) my_dict.update({'d': 4})
d) Both b and c
What will be the output of the following code?
for i in range(3):
print(i)
0
1
2
3
Which of the following is true about the while loop?
Which of the following is true about the for loop?
A for loop is a control flow statement that allows code to be executed repeatedly based on a fixed number of iterations.
What will be the output of the following code?
my_list = [1, 2, 3]
my_list[3] = 4
print(my_list)
[1, 2, 3, 4]
[1, 2, 3, None]
[1, 2, 3]
What will be the output of the following code?
my_list = [0, 1] * 2
print(my_list)
[0, 2]
What will be the output of the following code?
in python
for i in range(5):
if i == 2:
break
print(i)
else:
print('Completed')
0 1 2 Completed
0 1 Completed
