+ 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)
4 Respuestas
+ 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
+ 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.
+ 1
Thank you everyone :)