beginner-coding-concepts/functions.py

17 lines
485 B
Python
Raw Normal View History

2024-10-04 13:32:55 +00:00
import datetime
def calculate_age(dateOfBirth):
today = datetime.datetime.now()
age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day))
return age
def print_result(age):
if age >= 18:
print("You are " + str(age) + "! Enjoy the film")
else:
print("Sorry you aren't old enough you are only " + str(age))
dateOfBirth = datetime.datetime(1995, 9, 20)
age = calculate_age(dateOfBirth)
print_result(age)