Python/🐍 Python Foundations/Control Flow

Control Flow

Control flow in Python uses if/elif/else for conditionals and for/while for loops. Python uses indentation to define code blocks.

Guided Example

# Example: FizzBuzz
for i in range(1, 6):
    if i % 3 == 0:
        print("Fizz")
    elif i % 2 == 0:
        print("Even")
    else:
        print(i)

Practice Problems (0/4 solved)

Easy

Even or Odd

Print "Even" if the number is even, "Odd" if odd. num = 7

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Easy

Sum Numbers 1 to N

Calculate and print the sum of numbers from 1 to 10 using a for loop.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Medium

Count Vowels

Count and print the number of vowels (a, e, i, o, u) in the string "hello world".

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Medium

Fibonacci Sequence

Print the first 8 Fibonacci numbers, each on a new line. Start with 0, 1.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...