Solution: Birthday Calculator
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.
Solution: Birthday Calculator
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!")