Apr-05-2019, 06:37 PM
(Apr-05-2019, 05:50 PM)nilamo Wrote:and so?(Apr-05-2019, 04:07 PM)Evgeniy2019 Wrote:else: age = (year - birth_year) - 1
Don't think about code, just think about logic. This code will only run if the birth year is less than, or equal to, the current year. Which means either someone born this year (or at some point in the future). What should that person's age be?
import datetime # Step 2 birth_day = int(input("Day of birth: ")) birth_month = int(input("Month of birth: ")) birth_year = int(input("Year of birth: ")) day = int(datetime.date.today().day) month = int(datetime.date.today().month) year = int(datetime.date.today().year) # Step 3 if birth_month < month: age = year - birth_year else: age = (year - birth_year) - 1 # Step 4 a = age b = (month - birth_month) c = (day - birth_day) print(f"Your age: {a} years, {b} months, {c} days")