我无法使位于底部的位起作用(不要在if语句中打印该位,而是回到程序顶部)。
这是我到目前为止获得的代码。
我已经尝试过休息一下并添加一些继续,但是我什么也没做。
while True:
while True:
numberOne = int(input("Enter a number between number 0 and 10"))
numberTwo = int(input("Enter a seccond number between number 0 and 10"))
if numberOne > 0 and numberTwo < 10 and numberTwo < 10 and numberTwo > 0:
print (numberOne + numberTwo)
break
break
if numberOne < 0 or numberOne > 10 or numberTwo > 10 or numberTwo < 0:
print("These numbers are not imbetween 0 and 10 ")
我希望输出为“这些数字不在0到10之间”,然后再次执行脚本。
答案 0 :(得分:0)
while True:
numberOne = int(input("Enter a number between number 0 and 10"))
numberTwo = int(input("Enter a seccond number between number 0 and 10"))
if 1 < numberOne < 10 and 1 < numberTwo < 10:
print(numberOne + numberTwo)
elif 0 > numberOne > 10 or 0 > numberTwo > 10:
print("These numbers are not imbetween 0 and 10 ")
或:
i = True
while i:
numberOne = int(input("Enter a number between number 0 and 10"))
numberTwo = int(input("Enter a seccond number between number 0 and 10"))
if 1 < numberOne < 10 and 1 < numberTwo < 10:
print(numberOne + numberTwo)
i = False
elif 0 > numberOne > 10 or 0 > numberTwo > 10:
print("These numbers are not imbetween 0 and 10 ")
我并没有真正从这个问题中得到预期的结果。
答案 1 :(得分:0)
我相信下面的代码可以使用,请确认这是您想要的方式
while True:
numberOne = int(input("Enter a number between number 0 and 10: "))
numberTwo = int(input("Enter a seccond number between number 0 and 10: "))
if numberOne < 0 or numberOne > 10 or numberTwo > 10 or numberTwo < 0:
print("Numbers not between 0 and 10! ")
if numberOne > 0 and numberOne < 10 and numberTwo < 10 and numberTwo > 0:
print(numberOne + numberTwo)
答案 2 :(得分:0)
您可以执行此操作,而无需使用break
。还不是很清楚,您到底想做什么,但是此代码将检查数字,然后求和并打印或仅打印,然后继续循环:
while True:
numberOne = int(input("Enter a number between number 0 and 10: "))
numberTwo = int(input("Enter a seccond number between number 0 and 10: "))
if (numberOne in range(1,10)) and (numberTwo in range(1,10)):
print (numberOne + numberTwo)
else:
print("These numbers are not between 0 and 10 ")