+ 2
Why is the last elif statement not working ?
3 Réponses
+ 3
Instead of using "or", you could also use the membership operator "in":
...
elif o_p in 'x*':
print(num_1 * num_2 )
elif o_p in '/÷':
print(num_1 / num_2 )
+ 1
you need to do it like this:
num_1 = int(input('Enter a number'))
o_p = input('enter an operator')
num_2 = int(input('Enter a second number '))
if o_p == '+':
print(num_1 + num_2 )
elif o_p == '×' or o_p == '*':
print(num_1 * num_2 )
elif o_p == '/' or o_p == '÷':
print(num_1 / num_2 )
otherwise
elif o_p == '×' or '*':
this means if o_p is not 'x' then pick '*' and return (exit function). this way it kept picking up '*' no matter what symbol you place except for the upper one which is '+'
0
If the elif statement is not typed correctly, it will not work. Make sure you have typed the condition correctly