这只是一些代码,我想找到一种无需每次按f5即可运行代码的方法。我正在寻找调用输入变量的命令或方法。因为当我将打印(x)放入IDLE外壳时,它会给我输入值。我可以使用无限循环,但我想知道是否有可能?
x = int(input("Please enter an integer: "))
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('Zero')
elif x == 1:
print('Single')
else:
print('More')
答案 0 :(得分:3)
您可以使用无限循环:
while (True):
x = int(input("Please enter an integer: "))
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('Zero')
elif x == 1:
print('Single')
else:
print('More')