forked from JoinCODED/TASK-Python-Age-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathage_calculator.py
More file actions
32 lines (25 loc) · 724 Bytes
/
age_calculator.py
File metadata and controls
32 lines (25 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from datetime import datetime
def check_birthdate(year, month, day):
# write code here
birthdate = datetime(year, month, day)
today = datetime.now()
if today > birthdate:
return True
else:
return False
def calculate_age(year, month, day):
# write code here
age = datetime.now() - datetime(year, month, day)
age_in_years = age.days/365
print("You are %d years old" % (age_in_years))
def main():
# write main code here
year = int(input("Enter year of birth: "))
month = int(input("Enter month of birth: "))
day = int(input("Enter day of birth: "))
if check_birthdate(year, month, day):
calculate_age(year, month, day)
else:
print("The birthdate is invalid")
if __name__ == '__main__':
main()