AyanUpadhaya

Check Which Day Of The Year in Python

May 21st, 2021 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. # The program checks what day it was or is of the year
  2. # The program is written on mathematical calculation
  3. # Script wrote by Ayan, contact : ayanu881@gmail.com
  4.  
  5.  
  6. #month representing values
  7.  
  8. def main():
  9.     months={
  10.         "jan":1,
  11.         "feb":4,
  12.         "mar":4,
  13.         "apr":0,
  14.         "may":2,
  15.         "jun":5,
  16.         "jul":0,
  17.         "aug":3,
  18.         "sep":6,
  19.         "oct":1,
  20.         "nov":4,
  21.         "dec":6
  22.     }
  23.     days_in_week=["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]
  24.  
  25.     CURRENT_YEAR=2021
  26.  
  27.     while True:
  28.         year=int(input("year input:"))
  29.         wmonth=input("First three letters of month:")
  30.         day=int(input("Enter day:"))
  31.  
  32.         if len(wmonth)>3 or day>31:
  33.             print("Wrong Input, try again")
  34.             continue
  35.  
  36.         #get last numbers of the year, I call it year extension
  37.         year_ext=year-1900
  38.  
  39.         #check if the year is leap year so we can perform later calculation
  40.         def isleap_year():
  41.             if year_ext%4==0:
  42.                 return True
  43.             return False
  44.  
  45.         #default value
  46.         leap_day_cal=0
  47.        
  48.         if isleap_year():
  49.             if wmonth=="feb" or wmonth=="jan":
  50.                 leap_day_cal=(year_ext/4)-1
  51.             else:
  52.                 leap_day_cal=year_ext/4
  53.  
  54.         else:
  55.             leap_day_cal=year_ext/4
  56.  
  57.  
  58.  
  59.         total_cal=leap_day_cal+year_ext+day+months[wmonth]
  60.  
  61.         which_day_of_weak=days_in_week[int(total_cal%7)]
  62.  
  63.         if year<CURRENT_YEAR:
  64.             print(f"It was {which_day_of_weak}")
  65.         elif year==CURRENT_YEAR:
  66.             print(f"It is {which_day_of_weak}")
  67.         else:
  68.             print(f"It is {which_day_of_weak}")
  69.  
  70.  
  71.         option=input("Do you want to give nother try:(y/n)")
  72.        
  73.         if option.lower()=='y' or option in ['y']:
  74.             main()
  75.         else:
  76.             exit()
  77.  
  78.  
  79. if __name__=="__main__":
  80.     main()
  81.    
  82.  
  83.  
  84.  
  85.  
  86.  
Add Comment
Please, Sign In to add comment