Hi!
i have a school assignment in which i just cant figure out how to narrow the inputs to only calculate with allowed dates which only occur on leap years!
The program functions fine for all other dates, except for when the user enters values which i significant for leap years.
I have noticed that there it something with just that string that makes the whole program to skip the lines where otherwise the user are supposed to enter a value for day. I just cant figure out what the error might be. Please help!
How can I make the program to follow specifik instructions only on the month on january on leap years (value 2 or 14 in the code) which only allows the user to enter integers between 1 and 29?
This is the closest i have come:
Sorry for posting code incorrectly in previous post!
i have a school assignment in which i just cant figure out how to narrow the inputs to only calculate with allowed dates which only occur on leap years!
The program functions fine for all other dates, except for when the user enters values which i significant for leap years.
I have noticed that there it something with just that string that makes the whole program to skip the lines where otherwise the user are supposed to enter a value for day. I just cant figure out what the error might be. Please help!
How can I make the program to follow specifik instructions only on the month on january on leap years (value 2 or 14 in the code) which only allows the user to enter integers between 1 and 29?
This is the closest i have come:
elif month == 14: if (year+1)%4 == 0: if (year+1)%100 == 0: if (year+1)%400 == 0: while day>29 or day<1: day = int(input("Day:")) if day<1 or day>29: print("Out of allowed range 1 - 29")The following is the program in full:
year = 0 while year>9999 or year<1583: year = int(input("Year:")) if year<1583 or year>9999: print("Out of allowed range 1583 - 9999") month = 0 while month>12 or month<1: month = int(input("Month:")) if month<1 or month>12: print("Out of allowed range 1 - 12") if month == 1 or month == 2: month += 12 year -= 1 day = 0 if month == 4 or month == 6 or month == 9 or month == 11: while day>30 or day<1: day = int(input("Day:")) if day<1 or day>30: print("Out of allowed range 1 - 30") # Somewhere in the following lines the error occur! elif month == 14: if (year+1)%4 == 0: if (year+1)%100 == 0: if (year+1)%400 == 0: while day>29 or day<1: day = int(input("Day:")) if day<1 or day>29: print("Out of allowed range 1 - 29") elif month == 14: while day>28 or day<1: day = int(input("Day:")) if day<1 or day>28: print("Out of allowed range 1 - 28") else: while day>31 or day<1: day = int(input("Day:")) if day<1 or day>31: print("Out of allowed range 1 - 31") weekday = (day + 13*(month+1)//5 + year + year//4 - year//100 + year//400 ) % 7 if weekday == 0: print ("It is a Saturday") elif weekday == 1: print ("It is a Sunday") elif weekday == 2: print ("It is a Monday") elif weekday == 3: print ("It is a Tuesday") elif weekday == 4: print ("It is a Wednesday") elif weekday == 5: print ("It is a Thursday") elif weekday == 6: print ("It is a Friday") else: print ("Something went wrong")
Sorry for posting code incorrectly in previous post!
year = 0 while year>9999 or year<1583: year = int(input("Year:")) if year<1583 or year>9999: print("Out of allowed range 1583 - 9999") month = 0 while month>12 or month<1: month = int(input("Month:")) if month<1 or month>12: print("Out of allowed range 1 - 12") if month == 1 or month == 2: month += 12 year -= 1 day = 0 if month == 4 or month == 6 or month == 9 or month == 11: while day>30 or day<1: day = int(input("Day:")) if day<1 or day>30: print("Out of allowed range 1 - 30") # Somewhere in the following lines the error occur! elif month == 14: if (year+1)%4 == 0: if (year+1)%100 == 0: if (year+1)%400 == 0: while day>29 or day<1: day = int(input("Day:")) if day<1 or day>29: print("Out of allowed range 1 - 29") elif month == 14: while day>28 or day<1: day = int(input("Day:")) if day<1 or day>28: print("Out of allowed range 1 - 28") else: while day>31 or day<1: day = int(input("Day:")) if day<1 or day>31: print("Out of allowed range 1 - 31") weekday = (day + 13*(month+1)//5 + year + year//4 - year//100 + year//400 ) % 7 if weekday == 0: print ("It is a Saturday") elif weekday == 1: print ("It is a Sunday") elif weekday == 2: print ("It is a Monday") elif weekday == 3: print ("It is a Tuesday") elif weekday == 4: print ("It is a Wednesday") elif weekday == 5: print ("It is a Thursday") elif weekday == 6: print ("It is a Friday") else: print ("Something went wrong")