从Python代码开始,当我们有任意用户inpu时

2024-04-19 18:58:27 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从头开始代码再检查用户输入:

这里用户可以选择负值和正值,但不能选择01

如果用户写入01,我应该怎么做才能再次启动另一个输入的代码

inp  = float(input("PLEASE ENTER VALUE: "))
for xx in range(1,820):
    A = dfimppara.iloc[xx, 1]
    B = dfimppara.iloc[xx, 2]
    lim = Ju - Jl
    if inp<0:
        if lim > 1:
            pass
        else:
            print('You are calculating the entire possible J')
            print('ans=',A,'-->', B,'Tex =', ET(xx))
    if inp==0 or inp==1:
        #I want the code to start at beginning to use another inp
    else:
        if Ju==inp:
            print('ans=',A,'-->', B,'Tex =', ET(xx))

Tags: the代码用户ifelseettexprint
2条回答

使用while循环:

inp = 0
while (inp == 1 or inp == 0):
    inp  = float(input("PLEASE ENTER VALUE: "))
while True:
    inp  = float(input("PLEASE ENTER VALUE: "))
    if inp==0 or inp==1:
        print('Please use another input')
    else:
        for xx in range(1,820):
            A = dfimppara.iloc[xx, 1]
            B = dfimppara.iloc[xx, 2]
            lim = Ju - Jl
            if inp<0:
                if lim > 1:
                    pass
                else:
                    print('You are calculating the entire possible J')
                    print('ans=',A,' >', B,'Tex =', ET(xx))
            else:
                if Ju==inp:
                    print('ans=',A,' >', B,'Tex =', ET(xx))
        break 

相关问题 更多 >