python'或'不适用于

时间:2018-03-31 12:12:06

标签: python loops while-loop boolean operators

print ('Welcome to Calculator')
a = int(input('Enter your first value'))
b = int(input('Enter your second value'))
print ('''Addition - type 1
Subtraction - type 2
Multiplication - type 3 
Division - type 4''')
procedure = input('Enter a option')
while (procedure != '1') or (procedure != '2') or (procedure != '3') or (procedure != '4'):
    procedure = input('Please choose the correct option')
def process ():
    if procedure == '1':
        print (a+b)
    elif procedure == '2':
        print(a-b)
    elif procedure == '3':
        print (a*b)
    elif procedure == '4':
        print (a/b)
    else:
        print('There is some error in code')
process ()

在这个中,我希望只要过程的值不是1,2,3,4,循环就会继续,但是循环继续循环。请告诉错误如何正确执行

1 个答案:

答案 0 :(得分:1)

用AND替换OR,然后查看结果。  想到AND(union(联合))和OR(∩(交集))的意义以及你所写的条件,你一定会明白什么是错的...