One of my python loops is working perfectly while the other one is completely broken:
omonth = int(input('Digite o mês do seu nascimento: '))
while True:
if int(omonth) not in (1,12):
omonth = int(input('Digite o mês do seu nascimento: '))
else:
break
oday = int(input('Digite o dia do seu nascimento: '))
while True:
if int(oday) not in (1,31):
day = int(input('Digite o mês do seu nascimento: '))
else:
break
I'm trying to use a while loop to keep asking for an input when incorrect information is typed, and the first loop (omonth) is working perfectly, however the second loop (oday) repeats the input no matter what I type and never breaks.
Hello from a fellow brazilian!
That's happening because on this part of the code
You're attributing a value to the variable
dayinstead ofodayinside your if conditional.But besides that, your code has a bunch of flaws and will not work correctly.
First of all, this condition
checks if
omonthis equal to 1 or 12, not if it's in between them. The same logic applies to theodayloop.Second, the
intfunction inint(omonth)is redundant since you're already usingint(input())A better (and correct) implementation of your code would be: