Skip to content

Commit ad7c222

Browse files
committed
efficient_age_calculation
1 parent cce2ef0 commit ad7c222

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

TIME SCRIPTS/Age calculator/age.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Birth_Year = int(input("Enter your birth year: "))
66

7-
currentDateTime = datetime.datetime.now()
7+
currentDateTime = datetime.datetime.today()
88
date = currentDateTime.date()
99
year = date.strftime("%Y")
1010

TIME SCRIPTS/Age calculator/age1.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from datetime import date
2+
from dateutil.relativedelta import relativedelta
3+
n = input("Enter your name buddy ")
4+
birth_str = input('Enter the date you were born, in format YYYY-MM-DD: ')
5+
try:
6+
birth = date.fromisoformat(birth_str)
7+
except ValueError:
8+
print("Don't you know your birthday?")
9+
exit()
10+
11+
age = relativedelta(date.today(), birth)
12+
print(f'Wohoo {n} is {age.years} years, {age.months} months and {age.days} days old.')

0 commit comments

Comments
 (0)