noknow.dev
Sign inSign up
Course overview
Python Fundamentals
0 / 6 lessons0%

Getting Started

  • Hello, World!
  • Variables and Types
  • Working with Strings

Decisions & Loops

  • if / elif / else
  • for Loops and range()

Functions

  • Writing Your Own Functions

if / elif / else

0m 00s

Decisions in Python

Python uses indentation instead of curly braces. The colon after the condition is required:

score = 85

if score >= 90:
    print("A")
elif score >= 70:
    print("B")
elif score >= 50:
    print("C")
else:
    print("F")

Important: indentation must be consistent — always 4 spaces (Python standard).

Comparison operators

x == y   # equal
x != y   # not equal
x > y    # greater than
x < y    # less than
x >= y   # greater than or equal

# Logical operators
x > 0 and x < 10   # both conditions must be true
x < 0 or x > 100   # at least one condition must be true
not True            # False

Your task

Write a function traffic_light(color):

  • "red" → "Stop!"
  • "yellow" → "Caution!"
  • "green" → "Go!"
  • anything else → "Unknown color"
Back
pythonCtrl+Enter to run
Output

Click "Run" to execute your code.