GCGrowCarrer

Conditionals

Locked

Lesson 5 of 60 · Syntax · Easy

Input and OutputNext: Loops

Finish these first:Operators and Expressions →Or pass the tests below to unlock it now.

1

The big idea

An if statement lets your program make a decision. It checks a condition, and only runs the indented code underneath when that condition is True: Remember two tiny Python rules: put a colon : at the end of the if line, and indent the line underneath with 4 spaces (press Tab).

Think of it like this: Think of an `if` statement like a signpost on a trail: if the rule is true, follow the indented path underneath it.
Key words (tap to learn):
2

Read the lesson

An if statement lets your program make a decision. It checks a condition, and only runs the indented code underneath when that condition is True:

score = 92
grade = ""
if score >= 90:
    grade = "A"

Remember two tiny Python rules: put a colon : at the end of the if line, and indent the line underneath with 4 spaces (press Tab).

3

Quick check

What symbol goes at the end of a Python `if` line?

4

Your challenge

2 sample tests, 1 hidden

Write an if check: when age >= 18, set status = "adult".

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to java.conditionals (95% overlap). Same logic; Java uses braces and `&&`/`||`, Python uses indentation and `and`/`or`.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Conditionals.

Mastery0%

Learn this first

Opens up next