M03 - Decision Statements Flashcards
1
Q
Input Function Syntax
A
input(“Gather some input”)
2
Q
Input Function defaults to:
A
String
3
Q
Convert input to 1. integer; 2. float syntax
A
- int(input(“Gettin that input”))
2.
float(input(“Gettin that input”))
4
Q
If syntax
A
if condition :
(tab) statement1
(tab) statement2
(tab) etc.
5
Q
3 general rules when using “If” statements
A
- Begins with “if” followed by condition that will be evaluated as True or False
- Next line is a block of statements. These MUST be consistently indented. It is REQUIRED or won’t be executed
- If the condition is determined “False” then the statements are skipped
6
Q
if-else statement
A
Used when we need an outcome for both True AND False conditions
7
Q
if-else syntax
A
if condition :
(tab) trueStatement1
(tab) etc.
else :
(tab) falseStatement1
(tab) etc.
8
Q
2 general rules for if-else statements
A
- Make sure that if statement and else statement are aligned
- Make sure the statements under if and else statements are consistently indented
9
Q
if-elif-else syntax
A
if condition :
(tab) statement
elif condition : (tab) statement ....................................... else : (tab) statement
*NOTE: if, elif, and else are all equally indented