Iteration Flashcards

1
Q

Definition of a while loop?

A

while i < 5:
print(“Hello”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Definition of a for loop?

A

names = [“Mark”, “Ray”, “Pavel”]

for name in names:
print “Hello “ + name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Definition of a range loop?

A

for i in range(len(list)):
print (list[i])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the result of:
for i in range(5):
print(i)

A

0
1
2
3
4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly