Week 5 Flashcards

(7 cards)

1
Q

How do you make a choice between multiple options depending on a statement?

A
"elif"
e.g.
if condition 1:
   do thing 1
elif condition 2:
   do thing 2
.....
else:
   do thing N
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of loops?

A

Allows an operation to be done multiple times without writing a line of code multiple times

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

What does the while loop do?

A

e.g.
while condition:
do thing X
It keeps repeating thing X as long as condition remains true

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

When does a loop become infinite?

A

If the condition never becomes false

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

What should you first do with your loop?

A

Make sure it runs the way you want (initialise sentry)

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

When do numbers (float and int) evaluate to False?

A

If they are 0. Otherwise it is True

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

When do strings evaluate to False?

A

If it is an empty string (“ “). Otherwise it is true

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