Python Exercise 1.2: Age Calculator
Create a Python program that asks for the user's birth year and calculates their current age.
Your program should:
- Ask the user for their Birth Year (integer).
- Get the Current Year (e.g., 2025).
- Calculate the Age by subtracting the birth year from the current year.
- Print the result in a friendly sentence.
Bonus Challenge: Handle the case where they haven't had their birthday yet this year (requires asking for birth month/day). For this basic exercise, we will assume the birthday has passed.
Sample Interaction:
Solution
Here is how you can solve this using the datetime module to get the real current year automatically.
Key Concepts:
int()converts the input string to a number so we can do math.import datetimeallows us to work with real dates.datetime.date.today().yearfetches the system's current year dynamically.