This question already has an answer here:
I'm currently constructing a program which gives me the weekday of a certain date through the Zellers congruence-algorithm.
I'm perhaps half-way through or such, but I'm currently stuck because my last elif-statement when asking for a daynumber gets ignored. I don't know why since I specifically typed in month == 2, so it should display "Out of allowed range 1-28" when I type in a number that is higher, but it won't execute. Instead, the program executes the second elif-statement even if the month is "2" (february). Any clues?
while True:
year = int (input ("Year: "))
if 1583 <= year <= 9999:
break
else:
print ("Out of allowed range 1583-9999")
while True:
month = int (input ("Month: "))
if 1 <= month <= 12:
break
else:
print ("Out of allowed range 1-12")
while True:
day = int (input ("Day: "))
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
if 1 <= day <= 31:
break
else:
print ("Out of allowed range 1-31")
elif month == 4 or 6 or 9 or 11:
if 1 <= day <= 30:
break
else:
print ("Out of allowed range 1-30")
elif month == 2:
if 1 <= day <= 28:
break
else:
print ("Out of allowed range 1-28")
Aucun commentaire:
Enregistrer un commentaire