Implement the same exercise as Exercise 1 (Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old), except don’t explicitly write out the year. Use the built-in Python datetime
library to make the code you write work during every year, not just the one we are currently in.
To figure out the year in which someone will turn 100, we need to take the current year, subtract their current age, and add 100. We use the datetime
library to get the current year, the input()
function (see exercise 1) to ask the user their name and age, and f-strings (see exercise 38) to print out the result.
Take a look at the difference between this solution and the hard-coded one in exercise 1, where the year does not update automatically.