#julian2.py #calculate julian date of any year/month/day input month_names = {1:"January",2:"February",3:"March",4:"April",5:"May",6:"June",\ 7:"July",8:"Auguust",9:"September",10:"October",11:"November",12:"December"} day, month, year = map(int,input("Enter day, month, and year in dd/mm/yyyy format: ").split('/')) if not 1<=month<=12: print( "bogus month. Bye!") quit() elif not 1<=day<=31: print( "bogus day. Bye!") quit() elif year < 1753: print( "Sorry, calendar was wacky before 1753. Bye!") quit() #test for leapyear. #a year is a leap year if evenly divisible by 4 but not also evenly #divisible by 100 unless also evenly divisible by 400. #I.e. century years are not normally leap years unless they are also 400 #years. 1800, 1900, 2100 are not leap years, but 2000 is. if year%4==0 and year%100!=0 or year%400==0: is_leap = True else: is_leap = False #test that month day combo is valid. have already checked that day is <= 31 #So know that 31 day months are valid. if month in [4, 6, 9, 11]: #30 day months if day > 30: #i.e. is 31 print(month_names[month],"has only 30 days. Bye!") quit() elif month == 2: #Feb. if not is_leap and day > 28: #not a leap year print( "February has only 28 days this year. Bye!") quit() elif is_leap and day > 29: #is leap year print( "February has only 29 days this year. Bye!") quit() #determine the number of days in all the previous months month_days = [31,28,31,30,31,30,31,31,30,31,30,31] previousMonthDays = sum(month_days[:month-1]) if month>2 and is_leap: previousMonthDays += 1 #Feb 29 julian = previousMonthDays + day #plus this month's day print(day,month_names[month],year,"is Julian date: ", julian)