How can I check with a inputed date if that date of birthday is under 18?
year=int(input("Year born: "))
month = int(input("Month born: "))
day = int(input("Day born: "))
date = date(year,month,day)
What code can I use with date.today()
in order to check if user is under 18? Because if I substract 2022- year it could be under 17 because he was born in December
UPDATE:
def is_under_18(birth):
year=int(input("Year born: "))
month = int(input("Month born: "))
day = int(input("Day born: "))
date = date(year,month,day)
now = date.today()
return (
now.year - birth.year < 18
or now.year - birth.year == 18 and (
now.month < birth.month
or now.month == birth.month and now.day <= birth.day
)
)
Should it be like this? I didn't understand. And I would also like to add an if
he is older than 18, then print("You are over 18")