-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathage_in_numbers.py
27 lines (20 loc) · 1.07 KB
/
age_in_numbers.py
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
import time
import datetime
class YourAgeInNumber:
def __init__(self, b_day, b_month, b_year):
self.b_day = b_day
self.b_month = b_month
self.b_year = b_year
self.current_day = datetime.date.today().strftime("%d")
self.current_month = datetime.date.today().strftime("%m")
self.current_year = datetime.date.today().strftime("%Y")
def cal_day(self):
return abs(int(self.current_day) - self.b_day)
def cal_month(self):
return (int(self.current_month) - self.b_month) + 12 if int(self.current_month) < self.b_month else abs(int(self.current_month) - self.b_month)
def cal_year(self):
return (int(self.current_year) - self.b_year) - 1 if int(self.current_month) < self.b_month or (self.current_month == self.b_month and int(self.current_day) > self.b_day) else abs(int(self.current_year) - self.b_year)
def __str__(self):
return "You\'re {} Years {} month and {} days old".format(self.cal_year(),self.cal_month(),self.cal_day())
a = YourAgeInNumber(b_day=17,b_month=9,b_year=1982)
print(a)