How to use these exercises

Reading tutorials builds recognition; writing code builds skill. Try each exercise before opening the solution, run it, break it, then compare. Each one takes 5–15 minutes. Every exercise runs on the Coding Python app, which also has 12 auto-checked challenges and 112 quiz questions if you want scored practice.

Level 1: basics

1. Even or odd

Ask for a number and print whether it is even or odd.

n = int(input("Number: "))
print("even" if n % 2 == 0 else "odd")

2. Temperature converter

Convert Celsius to Fahrenheit for 0, 10, 20 … 100 in a table.

for c in range(0, 101, 10):
    print(f"{c:>4}°C = {c * 9 / 5 + 32:>6.1f}°F")

3. Sum of digits

Given 4921, print 16.

n = 4921
print(sum(int(d) for d in str(n)))
16

4. Count vowels

s = "Programming in Python"
print(sum(1 for ch in s.lower() if ch in "aeiou"))
5

5. Reverse words

"learn python fast" → "fast python learn"

print(" ".join("learn python fast".split()[::-1]))
fast python learn

Level 2: loops and collections

6. Multiplication table

n = 7
for i in range(1, 11):
    print(f"{n} x {i:2} = {n * i}")

7. Largest without max()

nums = [12, 45, 2, 41, 31]
biggest = nums[0]
for x in nums[1:]:
    if x > biggest:
        biggest = x
print(biggest)
45

8. Palindrome check

Ignore case and non-letters: "A man, a plan, a canal: Panama" is a palindrome.

s = "A man, a plan, a canal: Panama"
clean = "".join(ch.lower() for ch in s if ch.isalnum())
print(clean == clean[::-1])
True

9. Word frequency

text = "red blue red green blue red"
freq = {}
for w in text.split():
    freq[w] = freq.get(w, 0) + 1
for w, n in sorted(freq.items(), key=lambda kv: -kv[1]):
    print(w, n)
red 3 blue 2 green 1

10. Prime numbers up to 50

primes = []
for n in range(2, 51):
    if all(n % p for p in primes if p * p <= n):
        primes.append(n)
print(primes)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

11. Remove duplicates, keep order

items = [3, 1, 3, 2, 1, 4]
seen, out = set(), []
for x in items:
    if x not in seen:
        seen.add(x); out.append(x)
print(out)
[3, 1, 2, 4]

12. Matrix transpose

m = [[1, 2, 3], [4, 5, 6]]
print([list(row) for row in zip(*m)])
[[1, 4], [2, 5], [3, 6]]

Level 3: functions and logic

13. FizzBuzz as a function

def fizzbuzz(n):
    return "FizzBuzz" if n % 15 == 0 else "Fizz" if n % 3 == 0 else "Buzz" if n % 5 == 0 else str(n)
print([fizzbuzz(i) for i in range(1, 16)])

14. Caesar cipher

def caesar(text, shift):
    out = []
    for ch in text:
        if ch.isalpha():
            base = ord("A") if ch.isupper() else ord("a")
            out.append(chr((ord(ch) - base + shift) % 26 + base))
        else:
            out.append(ch)
    return "".join(out)
secret = caesar("Hello, World!", 3)
print(secret, caesar(secret, -3))
Khoor, Zruog! Hello, World!

15. Binary search

def bsearch(sorted_list, target):
    lo, hi = 0, len(sorted_list) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        if sorted_list[mid] == target: return mid
        if sorted_list[mid] < target: lo = mid + 1
        else: hi = mid - 1
    return -1
print(bsearch([1, 3, 5, 7, 9, 11], 7), bsearch([1, 3, 5], 4))
3 -1

16. Flatten a nested list (recursion)

def flatten(xs):
    out = []
    for x in xs:
        out.extend(flatten(x) if isinstance(x, list) else [x])
    return out
print(flatten([1, [2, [3, 4]], 5]))
[1, 2, 3, 4, 5]

17. Anagram groups

words = ["listen", "silent", "enlist", "google", "gogole"]
groups = {}
for w in words:
    groups.setdefault("".join(sorted(w)), []).append(w)
print(list(groups.values()))
[['listen', 'silent', 'enlist'], ['google', 'gogole']]
Solve these in the app and check yourself with the built-in challenges — the Coding Python app runs real Python 3 on your phone, with examples, quizzes and challenges built in.
Get it free

Level 4: small programs

18. Number guessing game

import random
secret, tries = random.randint(1, 100), 0
while True:
    g = int(input("Guess: ")); tries += 1
    if g < secret: print("Higher")
    elif g > secret: print("Lower")
    else:
        print(f"Got it in {tries}!"); break

19. To-do list with a dictionary menu

todos = []
actions = {
    "a": lambda: todos.append(input("Task: ")),
    "d": lambda: todos.pop(int(input("Index: "))),
    "l": lambda: print(*[f"{i}. {t}" for i, t in enumerate(todos)], sep="\n"),
}
while (cmd := input("(a)dd (d)elete (l)ist (q)uit: ")) != "q":
    actions.get(cmd, lambda: print("?"))()

20. Bank account class

class Account:
    def __init__(self, owner): self.owner, self.balance = owner, 0
    def deposit(self, n):
        if n <= 0: raise ValueError("positive only")
        self.balance += n
    def withdraw(self, n):
        if n > self.balance: raise ValueError("insufficient funds")
        self.balance -= n
    def __repr__(self): return f"Account({self.owner!r}, {self.balance})"

a = Account("Ada"); a.deposit(100); a.withdraw(40); print(a)
try: a.withdraw(500)
except ValueError as e: print("Error:", e)
Account('Ada', 60) Error: insufficient funds

Finished all twenty? Move on to beginner Python projects, or take the Python quiz in the app to find gaps.

Frequently asked questions

How many Python exercises should I do a day?

Two or three focused exercises a day beats a ten-hour binge once a week. Consistency builds the pattern recognition that makes code feel natural.

Where can I practise Python on my phone?

The Coding Python app for Android runs real Python on the device and includes 12 self-checking challenges and 112 quiz questions, so you can practise anywhere.

What should I do after these beginner exercises?

Build a small project end to end: a to-do CLI, a quiz game, a budget tracker. Projects force you to combine concepts and to read documentation.

Are these exercises suitable for interview preparation?

The Level 3 exercises (binary search, anagram grouping, recursion, Caesar cipher) are classic warm-ups. For interviews, follow with dedicated algorithm practice.