1. The if statement controls the program by changing its behaviour depending on the user's input. This why it is called a control structure.
2. There must be a colon after the if statement.
3. THE PRINT STATEMENT MUST BE INDENTED UNDER THE IF STATEMENT IN ORDER TO WORK.
4. if statements (and other control structures) control a chunk of code called a block. In Python, a statement is indented to indicate it belongs to a block.
5. The indentation must be to the same depth for every statement in the block and must be more than the statement controlling the block.
6. The block is often called the body of the control structure. Every control structure in Python has a colon followed by an indented block.
7. A single = is used for assignment. This is what we do to set variables.
8. A double == is used for comparison. This is what we do to check whether two things are equal.
9. If you do accidentally mix these up, Python will help by giving you a Syntax Error.
10. When you use an if statement Python evaluates a conditional expression to determine if it is True or False. If the expression evaluates to True then the block controlled by the if statement will be run.
11. If we change name the expression will evaluate to False and the block of code will not be run.
12. When we want to do one thing when a condition is True and do something different when a condition is False use else.
13. the condition in the else clause must be followed by a : character, just like the if statement.
14. The if/else statement is good for making decisions when there are only two options (friend or foe, true or false, wet or dry).
15. there are other ways to compare things (particularly when we are using numbers). We can use the following comparison operators in if statements:
OperationOperator equal to == not equal to != less than < less than or equal to <= greater than > greater than or equal to >=
16. Remember you have to convert input to an integer using the intfunction if you want to do numerical comparisons. Example: height = int(input("How many cm tall are you? ")) if height == 157: print("You are the same height as Kylie Minogue.") else: print("You are not the same height as Kylie Minogue.")
17. The body of an if statement may contain another if statement. This is called nesting.
18. use an elif clause. elif is an abbreviation for else and if together. It works like this: x = 5 if x < 3: print("x is less than three") elif x == 3: print("x is equal to three") else: print("x is greater than three")