Lesson 6 of 15

Control Flow

Control Flow

Python uses indentation to define blocks. There are no braces or begin/end keywords.

if / elif / else

x = 42
if x > 100:
    print("big")
elif x > 10:
    print("medium")
else:
    print("small")

Comparison Operators

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

Logical Operators

True and False  # False
True or False   # True
not True        # False

Ternary Expression

label = "even" if n % 2 == 0 else "odd"

match (Python 3.10+)

match command:
    case "quit":
        quit()
    case "help":
        show_help()
    case _:
        print("unknown command")

Your Task

Implement fizzbuzz(n) that returns:

  • "FizzBuzz" if n is divisible by both 3 and 5
  • "Fizz" if divisible by 3
  • "Buzz" if divisible by 5
  • The string representation of n otherwise
Pyodide loading...
Loading...
Click "Run" to execute your code.