Mini project — An age and birthday program in Python
This mini project is a practical example of using variables, data types and user input in Python. We will learn how to calculate the user's age and check whether their birthday has already passed this year.
1. Entering the data
First we ask the user for their year of birth and their birthday date:
name = input("Enter your name: ")
birth_year = int(input("Enter your year of birth: "))
birth_month = int(input("Enter your month of birth (1-12): "))
birth_day = int(input("Enter your day of birth (1-31): "))
2. Calculating the age
We use the current year and the user's data to calculate the age:
import datetime
today = datetime.date.today()
age = today.year - birth_year
# Check whether the birthday has passed
if (today.month, today.day) < (birth_month, birth_day):
age -= 1
print(f"{name}, you are {age} years old.")
3. A mini task for students
- Add checks that the entered dates are valid (month 1-12, day 1-31).
- Show a message if today is the user's birthday.
- Make a version that also asks for a friend's name and calculates the friend's age.
Hidden mini quiz — Basic Python skills
Click to check how well you understand input, variables and basic operations in Python!
Open the quiz
Mini quiz: Python basics
1. Which function lets the user enter data into a program?
2. What does the function input() return?
3. What will the following code print?
a = 5
b = 7
print(a + b)
4. Which line of code correctly converts the user's input into a whole number?
5. What will the output be?
name = "Mila"
print("Hello " + name)
Python mini game — Fill in the code 2
Practise basic operations and `input()` in Python. Fill in the blanks in the code and run the test to see whether you are right.
Game 1: Add two entered numbers
Enter code so that Python asks the user for two numbers and prints their sum:
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print(______)
Game 2: Product and difference
Fill in the blanks so that the program prints first the product and then the difference of the numbers:
a = int(input("a = "))
b = int(input("b = "))
print("Product:", ______)
print("Difference:", ______)
Extra tasks — practising input, variables and calculation (easier → harder)
These tasks are meant for 6th–7th grade students who have just started learning Python.
They do not use if statements, for or while loops — only input, calculation and output.
For extra practice with basic tasks (without branching), see this page too:
➡
Test preparation — basic tasks
Recommended tasks from there: 1, 2, 3, 4, 6, 7 and 8.
Task 1 — The sum and average of three numbers
Write a program that asks the user for three numbers and shows their sum and arithmetic mean.
Example input:
5
7
8
Example output:
The sum is: 20
The arithmetic mean is: 6.666666666666667
Task 2 — Today's and yesterday's temperature
The user enters today's and yesterday's temperature. Show the difference between them and the average of both temperatures.
Example input:
Today's temperature: 12
Yesterday: 8
Example output:
The difference is: 4
Average temperature: 10
Task 3 — The length of a journey
The user enters the speed of a car and the driving time in hours. Calculate how many kilometres it travelled.
Example input:
Speed: 60
Time: 2.5
Example output:
Distance travelled: 150 km
Task 4 — The cost of a purchase
The user enters the price of a product and the quantity. Show the total amount to pay and how big the discount would be if the price were reduced by 10%.
Example input:
Price: 1200
Quantity: 3
Example output:
Total: 3600
Discount amount (10%): 360
Task 5 — Converting minutes into hours and minutes
The user enters a total number of minutes. Show how many hours that is and how many minutes are left over.
Example input:
135
Example output:
Hours: 2
Minutes: 15
Task 6 — The perimeter and area of a rectangle
The user enters the lengths of the sides a and b.
Calculate the perimeter and the area.
Example input:
a = 5
b = 9
Example output:
Perimeter: 28
Area: 45
Task 7 — Swapping values without a third variable
Make a program that reads two numbers and swaps their values without using a third variable.
Example input:
a = 7
b = 12
Example output:
After swapping: a = 12, b = 7
8. A harder task — Calculating the time until midnight (mini competition level)
The user enters the current hour and minute (e.g. 17 and 42). Calculate how many minutes are left until midnight.
Example input:
Hour: 21
Minute: 30
Example output:
Minutes left until midnight: 210
