Hi I am a beginner in python, and I was trying to create a program where a date is entered and displayed in a program
I tried to implement loops for when the user entered a number outside the limits. For determining the month the while loop worked fine:
month = int(input("Which numeric month of the year were you born in?\n"))
while((month <=0) or (month >12)):
print("The Month must be within the range 12>= Month >0. Please enter the value again.")
print("\n")
month = int(input("Which numeric month of the year were you born in?\n"))
However, for the second part (below), determining the day, when the user inputs a value for the month of February, which is limited to 28 days, the looped message it shows is for a different condition (the third if statement in the day set) instead.
If you enter: 2 for month, and 30 for day. The message it loops is:
...30< month =<0
instead of showing:
28< month =<0
Can someone please help me figure out how to use the while statement properly?
My code is the following:
day = int(input("Which numeric day of the month were you born in?\n"))
while(month == 1,3,5,7,8,10,12):
if(day <=0) or (day >31):
print("For your selected month, the value for day must be within the range 31>= Day >0. Please enter the value again.")
print("\n")
day= int(input("Which numeric day of the month were you born in?\n"))
while(month ==2):
if(day <=0) or (day >28):
print("For your selected month, the value for day must be within the range 28>= Day >0. Please enter the value again.")
print("\n")
day= int(input("Which numeric day of the month were you born in?\n"))
while(month ==4,6,9,11):
if(day <=0) or (day >30):
print("For your selected month, the value for day must be within the range 30>=Day>0. Please enter the value again.")
print("\n")
day= int(input("Which numeric day of the month were you born in?\n"))
Note that I am limited to only beginner level python codes when using this. The most I can do beyond this is use for loops instead of while loops, but nothing more advanced than that.
The program should display the individuals birth date at the end of the program.
while(int(month)) in [4,6,9,11]:it doesn't look like you have break here.whileloop nicely :)