Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import datetime
  2.  
  3. now = datetime.datetime.now()
  4. now_year = int(str(now.year))
  5. now_month = int(str(now.month))
  6. now_day = int(str(now.day))
  7.  
  8. birth_day = int(input("Day of birth >>> "))
  9. birth_month = int(input("Month of birth >>> "))
  10. birth_year = int(input("Year of birth >>> "))
  11.  
  12. years = now_year - birth_year if now_month > birth_month else now_year - birth_year - 1
  13.  
  14. months = 12 + now_month - birth_month if now_month < birth_month else now_month - birth_month
  15.  
  16. days_in_months = {
  17.     "1": 31,
  18.     "2": 29 if now_year % 4 == 0 and now_year % 100 != 0 else 28,
  19.     "3": 31,
  20.     "4": 30,
  21.     "5": 31,
  22.     "6": 30,
  23.     "7": 31,
  24.     "8": 30,
  25.     "9": 31,
  26.     "10": 30,
  27.     "11": 31,
  28.     "12": 30
  29. }
  30.  
  31. days = 0
  32.  
  33. if birth_month < now_month:
  34.     for i in range(birth_month, now_month + 1):
  35.         days += days_in_months[str(i)]
  36. else:
  37.     for i in range(now_month, birth_month + 1):
  38.         days += days_in_months[str(i)]
  39.        
  40. days += birth_day
  41. days = int(days % 12) - 1
  42.  
  43. print(f"Your age is: {years} years {months} months {days} days!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement