-3
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 ()

In this, I want that whenever the value of the procedure is other than 1, 2, 3, 4 the loop goes on but in this the loop goes on forever. Please tell the error how to do it properly

Nick
  • 3
  • 1
  • 3
  • 6
    Think about it: What's the result of `x != 1 or x != 2`? Can that ever be `False`? If `x` is equal to one of the two values, can it also be equal to the other one? – Aran-Fey Mar 31 '18 at 12:13
  • It is working as you write it. You must not understand what is `or` or made a terrible mistake (in English, if either X or Y is true, then (X or Y) is true) – user202729 Mar 31 '18 at 12:14
  • can you tell the correct procedure – Nick Mar 31 '18 at 12:15
  • Replace all of the `or` statements with `and`. This is because you only want to continue the loop when none of the numbers are inputted. Let's say you typed '1'. That would return `false` for the first check but would return `true` for all the others so the loop would still continue. – Dan Mar 31 '18 at 12:17
  • Thanks a lot to all of you – Nick Mar 31 '18 at 12:18
  • @user202729 I know but I didn't think it would be considered a full answer. Oh well. I shall learn for next time :-) – Dan Mar 31 '18 at 12:23
  • @Dan It's not suitable for a comment either (as it does not suggest improvement). Also there are [short answers](https://stackoverflow.com/a/1555788/5267751). – user202729 Mar 31 '18 at 12:24
  • @user202729 Hey buddy I am just a beginner :-) – Nick Mar 31 '18 at 13:28

1 Answers1

1

replace ORs with ANDs, then see the result. think of meaning of AND (∪(union)) and OR (∩(intersection)) and the conditions you have written, you will surely understand what's wrong...