Solution: Birthday Calculator
Explore how to write a Python program that takes a user's birth year input, converts it into a number, calculates their age using arithmetic, and displays the result with a friendly message.
We'll cover the following...
We'll cover the following...
In this program, we’re asking the user for their birth year and then using it to calculate their age.
input()lets the user type something. Whatever they type is stored in the variablebirth_year.The value from
input()is always a string (text), so we useint()to convert it into a number before doing math.We store the current year (
2025) in another variable.The line
age = current_year - int(birth_year)calculates the user’s age.Finally,
print()displays a friendly message with their approximate age.
birth_year = input("What year were you born? ")
current_year = 2025
age = current_year - int(birth_year)
print("You are about", age, "years old!")Code asking for birth year and calculating age