Control Flow Flashcards

1
Q

Comparison Operators

A

==
!=
<
>
<=
>=

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

Boolean Operators

A

or - +
and - *
not # not True

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

if Statement

A

name = “Antony”

if name == “Debora”:
print(“Hi Debora!”)
elif name == “George”:
print(“Hi George!”)
else:
print(“Who are you?”)

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

Ternary Conditional Operator

A

<expression1> if <condition> else <expression2>

'kid' if age < 18 else 'adult'
</expression2></condition></expression1>

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

Switch Case (3.10 and above)

A

response_code = 502
match response_code:
case 200 | 201:
print(“OK”)
case 500 | 502:
print(“Internal Server Error”)
case str():
print(“Code is a string”)
case _:
print(“Invalid Code”)

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

While Loop and control loop Statements

A

spam = 0
while spam < 5:
spam = spam + 1
if spam == 3:
continue
elif spam == 5
break
print(“Hello, world.”)

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

For loop and range

A

pets = [“bella,” ‘milo”, “loki”]
for pet in pets:
print(pet)

for i in range(0, 10, 2): # range(start, stop, step)
print(i)

for i in range(5, -1, -1):
print(i) # 5 4 3 2 1 0

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

For Else statement

A

else выполняется только тогда, когда весь цикл был выполнен

for in [1, 2, 3, 4, 5]:
if i == 3:
break
else:
print(“only executed when no item is equal to 3”)

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

Ending a Program

A

import sys

sys.exit()

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