+ 1

Hey, i need help with my code. [SOLVED]

I'm trying to make a calculator and i've only started learning programming last week, so i'm using what i learnt from sololearn and logic so far. i want the user to input the numbers and what operation they want to execute so please help me! anything is appreciated. x = input("First Number: ") y = input("Second Number: ") z = input("Operation: ") #input add, sub, multi, or div if add in z: print("Result :" + x + y) elif sub in z: print("Result :" + x - y) elif multi in z: print("Result :" + x * y) elif div in z: print("Result :" + x / y)

17th Dec 2020, 6:18 PM
A Pizza
A Pizza - avatar
4 Answers
+ 2
Another thing, Instead of, if add in z: Do this, if z == 'add': Or this, if z == '+': # <-- If you are taking the operation symbol from input
17th Dec 2020, 11:54 PM
noteve
noteve - avatar
+ 4
You can make the calculator with a switch. The cases will be characters like:+,-,*,etc. In case '+' you will make and print a+b, etc. The inputs will be two numbers and a character(+,-,*,%,..). Also you can make the calculator with many if-else.
17th Dec 2020, 6:40 PM
Dimitris N. Kapoulas
Dimitris N. Kapoulas - avatar
+ 1
Thank you everyone :)
18th Dec 2020, 3:37 PM
A Pizza
A Pizza - avatar