Free Python practice exercises for beginners — 20 short problems with hidden solutions, ordered from first-day easy to first-project ready. No installs needed beyond Python itself: every exercise runs in a single file or straight in the Python shell.
Maintained by Korra Academy — the team behind Korra.Codes, where beginners learn to code with AI at their side.
- Read the exercise. Try it before opening the solution — struggling for ten minutes is where the learning happens.
- Click "Show solution" only to compare, or when truly stuck. There is usually more than one correct answer.
- Type the code yourself; don't copy-paste. Typing builds the muscle memory that reading never will.
1. Hello, you. Ask for the user's name with input() and greet them by name.
Show solution
name = input("What's your name? ")
print(f"Hello, {name}!")2. Simple sum. Ask for two numbers and print their sum. (Careful: input() gives you text.)
Show solution
a = float(input("First number: "))
b = float(input("Second number: "))
print(a + b)3. Age in dog years. Ask for an age and print it multiplied by 7.
Show solution
age = int(input("Your age: "))
print(f"That's {age * 7} in dog years.")4. Even or odd. Ask for a whole number and print whether it's even or odd.
Show solution
n = int(input("A whole number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")5. Temperature converter. Convert a Celsius temperature to Fahrenheit (F = C × 9/5 + 32).
Show solution
c = float(input("Celsius: "))
print(f"{c}°C is {c * 9 / 5 + 32}°F")6. Count to ten. Print the numbers 1 to 10, one per line, with a loop.
Show solution
for i in range(1, 11):
print(i)7. Times table. Ask for a number and print its times table up to 12.
Show solution
n = int(input("Which table? "))
for i in range(1, 13):
print(f"{i} x {n} = {i * n}")8. Sum of a hundred. Add up all numbers from 1 to 100 and print the total. (It should be 5050.)
Show solution
total = 0
for i in range(1, 101):
total += i
print(total) # or: print(sum(range(1, 101)))9. Guess the number. Pick a secret number, then keep asking the user to guess until they get it, saying "higher" or "lower" each time.
Show solution
import random
secret = random.randint(1, 20)
guess = None
while guess != secret:
guess = int(input("Guess (1–20): "))
if guess < secret:
print("Higher!")
elif guess > secret:
print("Lower!")
print("Got it!")10. FizzBuzz. Print 1 to 30 — but print "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for both. (A classic interview question.)
Show solution
for i in range(1, 31):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)11. Backwards. Ask for a word and print it reversed.
Show solution
word = input("A word: ")
print(word[::-1])12. Vowel counter. Count how many vowels are in a sentence.
Show solution
sentence = input("A sentence: ").lower()
count = sum(1 for ch in sentence if ch in "aeiou")
print(f"{count} vowels")13. Palindrome check. Say whether a word reads the same forwards and backwards ("level", "noon").
Show solution
word = input("A word: ").lower()
print("Palindrome!" if word == word[::-1] else "Not a palindrome.")14. Biggest and smallest. Given numbers = [4, 11, 2, 42, 7], print the largest and smallest without using max() or min() — then check yourself with them.
Show solution
numbers = [4, 11, 2, 42, 7]
biggest = smallest = numbers[0]
for n in numbers[1:]:
if n > biggest:
biggest = n
if n < smallest:
smallest = n
print(biggest, smallest) # check: max(numbers), min(numbers)15. Shopping list. Let the user add items one at a time; when they type "done", print the list sorted alphabetically.
Show solution
items = []
while True:
item = input("Add item (or 'done'): ")
if item == "done":
break
items.append(item)
print(sorted(items))16. Your first function. Write area_of_rectangle(width, height) that returns the area, and call it twice.
Show solution
def area_of_rectangle(width, height):
return width * height
print(area_of_rectangle(3, 4))
print(area_of_rectangle(2.5, 10))17. Word counter. Write a function that takes a sentence and returns how many words it contains.
Show solution
def word_count(sentence):
return len(sentence.split())
print(word_count("the quick brown fox")) # 418. Phone book. Store three names and phone numbers in a dictionary. Ask for a name and print the number, or "Not found".
Show solution
phone_book = {"Asha": "0121 001", "Ben": "0121 002", "Cal": "0121 003"}
name = input("Who? ")
print(phone_book.get(name, "Not found"))19. Letter frequency. Count how often each letter appears in a word, using a dictionary.
Show solution
word = input("A word: ").lower()
counts = {}
for ch in word:
counts[ch] = counts.get(ch, 0) + 1
print(counts)20. Rock, paper, scissors. The computer picks at random; the user picks; print who won. Best of one is fine — best of three is your bonus round.
Show solution
import random
options = ["rock", "paper", "scissors"]
computer = random.choice(options)
user = input("rock, paper or scissors? ").lower()
beats = {"rock": "scissors", "paper": "rock", "scissors": "paper"}
print(f"Computer chose {computer}.")
if user == computer:
print("Draw!")
elif beats[user] == computer:
print("You win!")
else:
print("Computer wins!")What Python exercises should a complete beginner start with? Start with input/output and arithmetic (exercises 1–5 here), then loops, then strings and lists, then functions. Twenty short, ordered problems beat one big project at the start — each exercise should take 5–20 minutes.
Do I need to install anything to practise Python? Only Python itself, free from python.org. Every exercise here runs in a single file or the Python shell — no libraries, no accounts, no setup beyond that.
Should I look at the solution if I'm stuck? Try for at least ten minutes first, and get your error messages read before your solutions. Then compare with the hidden solution, close it, and rewrite the answer from memory. Peeking is fine; copy-pasting teaches nothing.
Is it OK to use AI while doing beginner exercises? Yes — as a tutor, not a typist. Ask it to explain an error or hint at the next step, not to write the answer. If AI writes the code, you've practised prompting, not Python. That balance is exactly what we teach at korra.codes.
What comes after these 20 exercises? Build something tiny that's yours: a quiz, a dice game, a to-do list in the terminal. Then learn to read files and use one library well. Projects convert exercises into skill.
Korra Academy delivers live online tutoring across eight doors: Kids, Study, Career, Business, Tutor, Training, Bot and Codes. These are the working documents behind our own sessions at korra.one. MIT licensed.