如何不使用f5每次都在IDLE中调用输入变量

时间:2018-12-03 16:06:05

标签: python shell python-idle

这只是一些代码,我想找到一种无需每次按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')

1 个答案:

答案 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')
相关问题