Chapter 6.2 - If statement Flashcards
What are the control flow tools?
They control the flow of the program. Example, IF and For loop
What does the IF statement do?
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.
What is the structure of an IF statement?
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.
Do you need to add parentheses and braces for If statement? If not then what does Python use to execute these control flow statements?
No. Python uses indentation. Anything indented is identified as a block which is executed if the condition is evaluated true.
Write a script as an example for If/else statement
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”)