iteration Flashcards

1
Q

how to print every item/index in a list

A

eg. for i in shoppingList:
print(i)

and it will print
apples
banana
orange
mango

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

how to print every item/index in a 2D list

A

eg. shoppingList = [[“apples”, “2”], [“bananas”, “4”], [“oranges”, “3”]

for i in shoppingList:
for a in i:
print(a)

  • it will print
    apples
    2
    bananas
    4
    oranges
    3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how to print a number counter from 1 to 10

A

for i in range (1, 11):
print(i)
should print
1
2
3
4
5
6
7
8
9
10

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

how to print number counter 10 to 1 backwards

A

for i in range(10, 0, -1)
print(i)
should print
10
9
8
7
6
5
4
3
2
1

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

difference between while and for loop

A

know how many times program will be done in a for loop
dont know how many passes are in a while loop

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