0

It's only giving me the result of the first operation which is multiplied even if my input was the addition.

print('Calculator')
operation = input('Choose:\n Mltiply(*)\n Divise\(/)\n Add(+)\n Subbstract(-)\n ')
if operation == 'mutiply' or 'Multiply' or 'MULTIPLY' or '*':
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) * float(num2)
    print(result )
elif operation == 'DIVISE' or 'divise' or 'Divise' or '/':
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) / float(num2)
    print(result )
elif operation == 'Add' or 'add' or 'ADD' or '+':
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) + float(num2)
    print(result )
elif operation == 'Subbstract' or 'subbstract' or 'SUBBSTRACT' or '-':
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) - float(num2)
    print(result )
else:
    print('SYNTAX ERROR')
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
TNZ
  • 11
  • 3

2 Answers2

1

Use the in operator

elif operation in {'DIVISE', 'divise', 'Divise', '/'}:

for every if/else block.

EDIT: You can find a good explanation here: Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those?

bitflip
  • 3,436
  • 1
  • 3
  • 22
1

Use in

print('Calculator')
operation = input('Choose:\n Mltiply(*)\n Divise\(/)\n Add(+)\n Subbstract(-)\n ')
if operation.lower() in ['mutiply', '*']:
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) * float(num2)
    print(result )
elif operation.lower() in ['mutiply', '*']:
    num1 = input('Write Your number :')
    num2 = input('Write your next number :')
    result = float(num1) / float(num2)
    print(result )
..... replicate the above code for other operations ....

Why is your code always meet the fist condition?

operation == 'mutiply' or 'Multiply' or 'MULTIPLY' or '*' this always gives you True,

if 'Multiply':
     # Always return true
Rahul K P
  • 15,740
  • 4
  • 35
  • 52