#julian.py #calculate julian date of any year/month/day input #a program with lots of if statements and no loops year = int(input("Enter year: ")) month = int(input("Enter month number: ")) day = int(input("Enter day: ")) if month<1 or month>12: print( "bogus month. Bye!") quit() elif day<1 or 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==4 or month==6 or month==9 or month==11: #30 day months if day > 30: #i.e. is 31 if month == 4: print( "April has only 30 days. Bye!") elif month == 6: print( "June has only 30 days. Bye!") elif month == 9: print( "September has only 30 days. Bye!") elif month == 11: print( "November 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 previousMonthDays = 0 if month > 1: previousMonthDays += 31 #Jan if month > 2: previousMonthDays += 28 #Feb if is_leap: previousMonthDays += 1 #Feb 29 if month > 3: previousMonthDays += 31 #Mar if month > 4: previousMonthDays += 30 #Apr if month > 5: previousMonthDays += 31 #May if month > 6: previousMonthDays += 30 #Jun if month > 7: previousMonthDays += 31 #Jul if month > 8: previousMonthDays += 31 #Aug if month > 9: previousMonthDays += 30 #Sep if month > 10: previousMonthDays += 31 #Oct if month > 11: previousMonthDays += 30 #Nov julian = previousMonthDays + day #plus this month's day print( "Julian date: ", julian)