Chapter 6.2 - If statement Flashcards

1
Q

What are the control flow tools?

A

They control the flow of the program. Example, IF and For loop

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

What does the IF statement do?

A

The IF statement allows the program to evaluate if 1 condition is met, and to perform the appropriate action based on the result of the evaluation.

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

What is the structure of an IF statement?

A

If condition 1 is met do A
elif condition 2 is met do B
elif condition 3 is met do C
Else do E

elif stands for “else if” and you can have as many elif statements as you like.

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

Do you need to add parentheses and braces for If statement? If not then what does Python use to execute these control flow statements?

A

No. Python uses indentation. Anything indented is identified as a block which is executed if the condition is evaluated true.

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

Write a script as an example for If/else statement

A

userAge = Input(“Enter 80 or 30:”)
If userAge == “80”:
print(“You are a Boomer”)
print(“Congratulations! You could afford to buy a house”)
elif userAge == “33”:
print(“You are a millenial”)
print(“Sorry, you will be renting forever”)
else:
print(“You are not relevant to this conversation”)

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