Reading about Python is not enough: you learn it by solving small problems. Here are 10 beginner exercises, from very easy to "nice, I did that". Try each one yourself first, then open the solution. Every solution has been run, and the output shown is exactly what Python prints.
1. SAY HELLO
Store your name in a variable and print Hello, NAME! using an f-string.
Show solution
name = "Mia"
print(f"Hello, {name}!")Hello, Mia!
2. EVEN OR ODD
Given a number, print even or odd.
Show solution
n = 17
print("even" if n % 2 == 0 else "odd")odd
3. SUM 1 TO 100
Add up all numbers from 1 to 100 with a loop.
Show solution
total = 0
for n in range(1, 101):
total += n
print(total)5050
Shortcut once you know it: sum(range(1, 101)).
4. BIGGEST NUMBER
Find the biggest number in a list without using max().
Show solution
nums = [4, 19, 7, 11]
best = nums[0]
for n in nums:
if n > best:
best = n
print(best)19
5. COUNT THE VOWELS
Count how many vowels (a, e, i, o, u) are in a word.
Show solution
word = "programming"
count = 0
for ch in word:
if ch in "aeiou":
count += 1
print(count)3
6. REVERSE A WORD
Print a word backwards and check if it is a palindrome (the same in both directions).
Show solution
word = "level"
print(word[::-1])
print(word == word[::-1])level
True
7. FIZZBUZZ
For 1 to 15: print Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both, otherwise the number.
Show solution
for n in range(1, 16):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
More on this classic in the FizzBuzz guide.
8. COUNT WORDS
Count how many times each word appears in a sentence, using a dictionary.
Show solution
text = "snek eats apple snek wins"
counts = {}
for w in text.split():
counts[w] = counts.get(w, 0) + 1
print(counts){'snek': 2, 'eats': 1, 'apple': 1, 'wins': 1}
9. A FUNCTION FOR AVERAGES
Write a function that returns the average of a list, and 0 for an empty list.
Show solution
def average(nums):
if not nums:
return 0
return sum(nums) / len(nums)
print(average([3, 4, 8]))
print(average([]))5.0
0
10. LEVEL UP
A player needs 100 XP per level. Given total XP, print the level and how much XP is left until the next one.
Show solution
xp = 345
level = xp // 100 + 1
left = 100 - xp % 100
print(f"Level {level}, {left} XP to go")Level 4, 55 XP to go
nums = [3, 8, 1]
print(sorted(nums)[-1] - min(nums))sorted(nums) is [1, 3, 8], so [-1] is 8. The minimum is 1. 8 - 1 = 7.WHAT NEXT?
Stuck on one? Each topic has its own guide: for loops, while loops, strings, dictionaries and functions.
PRACTICE IT, DON'T JUST READ IT
Want hundreds more? Snekcade has 42 levels of short Python challenges that run on your phone, with an explanation for every answer.
PLAY PRINT PLAINS ▸FAQ
What are good Python exercises for beginners?
Small problems that use one or two ideas: even or odd, summing numbers, finding the biggest item, counting letters, reversing text and FizzBuzz.
How should I practise Python as a beginner?
A little every day. Try the problem yourself first, then compare with a solution, then change the code and see what happens.
Do I need to install Python to practise?
No. Snekcade runs real Python in your browser or phone, so you can practise without installing anything.