Why is the last elif statement not working ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is the last elif statement not working ?

https://code.sololearn.com/c48M52F7hkD0/?ref=app

16th May 2020, 12:58 PM
Ugonna Muoneme
Ugonna Muoneme - avatar
3 Answers
+ 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 )
16th May 2020, 2:23 PM
Lothar
Lothar - avatar
+ 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 '+'
16th May 2020, 1:04 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
0
If the elif statement is not typed correctly, it will not work. Make sure you have typed the condition correctly
18th May 2020, 10:01 AM
Ketan Pal
Ketan Pal - avatar