15 Python Exercises for Beginners with Complete Solutions

Published on: May 6, 2026
Reading time: 4 minutes
Programador pensnado em frente à vários monitores com código na tela

Learning to program is like learning a new language. You need to practice every day to improve. Python is one of the most beginner-friendly languages for those who are starting out. Its clean and simple syntax allows you to focus on problem-solving logic rather than language complexity.

This article presents 15 Python exercises for beginners, organized from the easiest to the most challenging. Each exercise comes with a detailed solution and step-by-step explanations. You will learn fundamental concepts while solving real problems.

Before getting started, make sure you have Python installed on your computer. You can download it for free from the official website python.org. Use the latest version to ensure compatibility with all examples.

Exercise 1: Personalized Hello World

Problem: Create a program that asks for the user’s name and displays a personalized welcome message.

This is every beginner’s first program, but with a twist. Let’s make it interactive from the start.

Solution:

Python

# Ask for the user's name
name = input("What is your name? ")

# Display personalized message
print(f"Hello, {name}! Welcome to the world of Python programming!")
Pronto para executar

The input() function allows the program to receive user input. The text inside quotes appears as a prompt. The response is stored in the variable 'name'. The letter 'f' before the string allows inserting variables using curly braces {}.

Exercise 2: Age Calculator

Problem: Write a program that calculates a person's age based on their birth year.

This exercise introduces basic math operations and type conversion.

Solution:

Python

# Import module to get current year
from datetime import datetime

# Get current year
current_year = datetime.now().year

# Ask for birth year
birth_year = int(input("What year were you born? "))

# Calculate age
age = current_year - birth_year

# Display result
print(f"You are {age} years old or will turn {age} this year!")
Pronto para executar

The int() function converts text into an integer. This is necessary because input() always returns a string. The datetime module provides the current year automatically.

Exercise 3: Even or Odd

Problem: Create a program that checks whether a number is even or odd.

Here you learn about conditional structures and the modulo operator (%).

Solution:

Python

# Ask user for a number
number = int(input("Enter an integer: "))

# Check even or odd
if number % 2 == 0:
    print(f"The number {number} is EVEN")
else:
    print(f"The number {number} is ODD")
Pronto para executar

The % operator returns the remainder of a division. Even numbers divided by 2 always leave remainder 0. The if-else structure allows decision-making.

Exercise 4: Average of Three Grades

Problem: Calculate the average of three grades and determine if the student passed (average >= 7).

This exercise combines input, calculations, and decision-making.

Solution:

Python

# Ask for three grades
grade1 = float(input("Enter first grade: "))
grade2 = float(input("Enter second grade: "))
grade3 = float(input("Enter third grade: "))

# Calculate average
average = (grade1 + grade2 + grade3) / 3

# Show result
print(f"Your average is: {average:.2f}")

# Check result
if average >= 7:
    print("Congratulations! You PASSED!")
elif average >= 5:
    print("You are in RECOVERY")
else:
    print("Unfortunately, you FAILED")
Pronto para executar

The float() function converts text into decimal numbers. The format .2f limits output to two decimal places. The elif allows multiple conditions.

Exercise 5: Multiplication Table

Problem: Generate the multiplication table of a number chosen by the user.

This classic exercise introduces loops.

Solution:

Python

# Ask for a number
number = int(input("Enter a number to see its multiplication table: "))

print(f"\nMultiplication table for {number}:")
print("-" * 20)

for i in range(1, 11):
    result = number * i
    print(f"{number} x {i:2} = {result}")
Pronto para executar

The for loop repeats a block of code multiple times. The range(1, 11) function generates numbers from 1 to 10.

Exercise 6: Vowel Counter

Problem: Count how many vowels exist in a word or sentence.

This introduces string manipulation and iteration.

Solution:

Python

text = input("Enter a word or sentence: ")
vowels = "aeiouAEIOU"
count = 0

for letter in text:
    if letter in vowels:
        count += 1

print(f"The text '{text}' contains {count} vowels")

found_vowels = set()
for letter in text.lower():
    if letter in "aeiou":
        found_vowels.add(letter)

if found_vowels:
    print(f"Vowels found: {', '.join(sorted(found_vowels))}")
Pronto para executar

The in operator checks membership. The set() removes duplicates automatically.

Exercise 7: Prime Number

Problem: Check if a number is prime.

This improves logical thinking and loop optimization.

Solution:

Python

number = int(input("Enter a number: "))

if number < 2:
    print(f"{number} is not prime")
else:
    is_prime = True
    for divisor in range(2, int(number ** 0.5) + 1):
        if number % divisor == 0:
            is_prime = False
            break
    
    if is_prime:
        print(f"{number} is PRIME!")
    else:
        print(f"{number} is NOT prime")
Pronto para executar

Checking divisibility up to the square root improves performance.

Exercise 8: Fibonacci

Problem: Generate the first N numbers of the Fibonacci sequence.

A classic programming problem.

Solution:

Python

n = int(input("How many Fibonacci numbers? "))

if n <= 0:
    print("Enter a positive number")
elif n == 1:
    print("0")
else:
    fibonacci = [0, 1]
    for i in range(2, n):
        fibonacci.append(fibonacci[i-1] + fibonacci[i-2])
    print(fibonacci)
    print(f"Sum: {sum(fibonacci)}")
Pronto para executar

The append() method adds elements to a list.

Exercise 9: Palindrome

Problem: Check if a word is a palindrome.

Focus on string manipulation.

Solution:

Python

word = input("Enter a word: ")
clean = word.replace(" ", "").lower()
reverse = clean[::-1]

if clean == reverse:
    print("Palindrome!")
else:
    print("Not a palindrome")
Pronto para executar

The [::-1] slice reverses strings.

Exercise 10: Temperature Converter

Problem: Convert between Celsius, Fahrenheit, and Kelvin.

Solution:

Python

def c_to_f(c): return (c * 9/5) + 32
def c_to_k(c): return c + 273.15

choice = input("1: C→F, 2: C→K: ")
temp = float(input("Temperature: "))

if choice == "1":
    print(c_to_f(temp))
elif choice == "2":
    print(c_to_k(temp))
Pronto para executar

Functions help organize reusable logic.

Exercise 11: Shopping List

Problem: Manage a shopping list.

Solution:

Python

items = []

while True:
    cmd = input("add/remove/list/exit: ")
    if cmd == "add":
        items.append(input("Item: "))
    elif cmd == "list":
        print(items)
    elif cmd == "exit":
        break
Pronto para executar

Lists are dynamic and can grow over time.

Exercise 12: Guessing Game

Problem: Guess a random number.

Solution:

Python

import random
secret = random.randint(1, 100)

while True:
    guess = int(input("Guess: "))
    if guess == secret:
        print("Correct!")
        break
    elif guess < secret:
        print("Too low")
    else:
        print("Too high")
Pronto para executar

The random module generates random values.

Exercise 13: Simple CPF Validator

Problem: Validate a CPF format.

Solution:

Python

cpf = input("Enter CPF: ")
cpf = ''.join(filter(str.isdigit, cpf))

if len(cpf) == 11:
    print("Valid format")
else:
    print("Invalid CPF")
Pronto para executar

This is a simplified version focused on structure validation.

Exercise 14: Calculator

Problem: Build a calculator.

Solution:

Python

a = float(input("A: "))
b = float(input("B: "))
op = input("+ - * /: ")

if op == "+": print(a+b)
elif op == "-": print(a-b)
elif op == "*": print(a*b)
elif op == "/": print(a/b)
Pronto para executar

This combines conditionals and math operations.

Exercise 15: Text Analyzer

Problem: Analyze a text and provide statistics.

Solution:

Python

text = input("Enter text: ")

print("Characters:", len(text))
print("Words:", len(text.split()))
print("Digits:", sum(c.isdigit() for c in text))
Pronto para executar

This combines multiple concepts into a practical tool.

Conclusion and Next Steps

Congratulations on completing these 15 Python exercises. Keep practicing and building projects to improve your skills.

Frequently Asked Questions (FAQ)

1. What are these exercises?
They are beginner-friendly Python problems focused on logic and fundamentals.

2. Do I need to install anything?
Yes, install Python or use online tools like Colab.

3. Difficulty level?
From beginner to intermediate.

4. Time per exercise?
10 to 60 minutes.

5. Do they include solutions?
Yes.

6. Good for interviews?
Yes, great for logic training.

7. How to validate code?
Run and test with different inputs.

8. Are there tests?
Some include basic tests.

9. Can I expand them?
Yes, turn them into projects.

10. Where to ask questions?
Use comments or contact channels.

Share:

Facebook
WhatsApp
Twitter
LinkedIn

Article content

    Related articles

    Automation and Scripts
    Foto do Leandro Hirt

    How to compare two lists in Python and find the differences

    Comparing data is one of the most common and essential tasks in a programmer's day-to-day work. Whether you are synchronizing

    Ler mais

    Tempo de leitura: 10 minutos
    06/05/2026