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
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
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
4
Q
When does a loop become infinite?
A
If the condition never becomes false
5
Q
What should you first do with your loop?
A
Make sure it runs the way you want (initialise sentry)
6
Q
When do numbers (float and int) evaluate to False?
A
If they are 0. Otherwise it is True
7
Q
When do strings evaluate to False?
A
If it is an empty string (“ “). Otherwise it is true