我已经看到过这样的一些问题,但并没有真正得到我的答案 - 我对python和整个编程都很陌生并且我一直坚持这个while循环一段时间:
juveniles = int(input("How many juveniles are there?"))
while juveniles < 0:
print("Please enter a valid number of juveniles")
adults = int(input("How many adults are there?"))
目前,这段代码只重复了#34;请输入有效数量的青少年&#34;如果我输入一个小于0的数字(那里没有惊喜),我希望它继续问同样的问题,直到用户给出任何超过0的数字,并且一旦完成它移动到下一个变量(成人)。我怎么能这样做?
答案 0 :(得分:0)
您忘记更新值:
juveniles = int(input("How many juveniles are there?"))
while juveniles < 0:
print("Please enter a valid number of juveniles")
juveniles = int(input("How many juveniles are there?"))
adults = int(input("How many adults are there?"))