我不明白为什么当用户进入“0”循环不会退出。
def floatInput():
done = False
while not done:
integerIn = input("Please enter an integer < 0 to finish >: ")
try:
integerIn = int(integerIn)
except:
print("I was expecting an integer number, please try again...")
import sys
sys.exit()
if integerIn == "0":
done = True
else:
integers.append(integerIn)
return integers
最佳答案
def floatInput():
done = False
while not done:
integerIn = input("Please enter an integer < 0 to finish >: ")
try:
integerIn = int(integerIn)
except:
print("I was expecting an integer number, please try again...")
import sys
sys.exit()
上面的一切都很好,但是一旦你进行比较,你就会忘记你已经将输入强制转换为int。
if integerIn == "0":
应该是
if integerIn == 0:
关于python - 要求时,Python While循环不会退出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36605874/