Module 2

if

Making decisions in code.

Do this only if that is true

The if statement lets your program make decisions. It runs a block of code only when a condition is true.

PythonThe indented line runs only if the condition is true.
temperature = 35
if temperature > 30:
    print("Too hot")
Too hot

Notice two things: the colon at the end of the if line, and the indentation of the line below. Both are required. The indented code is the block that runs when the condition is true.

Your task

Write an if statement

  • If score is 85, print Pass when score is >= 70.
Remember

if condition: code to run when true The colon and the indentation are both required.