我的一个 python 循环工作正常,而另一个则完全损坏:
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
我尝试使用 while 循环在输入不正确的信息时继续要求输入,并且第一个循环(omonth)工作正常,但是第二个循环(oday)无论我输入什么都会重复输入,并且从不重复输入休息。
在第二个循环中,
day = int(input('Digite o mês do seu nascimento: '))
行包含错误。变量 day
被分配了用户输入的值,但它应该是 oday
。