Iteration Flashcards
1
Q
Definition of a while loop?
A
while i < 5:
print(“Hello”)
2
Q
Definition of a for loop?
A
names = [“Mark”, “Ray”, “Pavel”]
for name in names:
print “Hello “ + name
3
Q
Definition of a range loop?
A
for i in range(len(list)):
print (list[i])
4
Q
Output of…
range(5, 10)
range(5, 10, 2)
range(7, 15, 3)
range(9, 5, -1)
A
gives [5, 6, 7, 8, 9]
gives [5, 7, 9]
gives [7, 10, 13]
gives [9, 8, 7, 6]
5
Q
What is the result of:
for i in range(5):
print(i)
A
0
1
2
3
4