I am practicing with coding trying to improve myself and not just follow tutorials all the time. I was making a simple calculator but wanted to reduce the amount of duplicate code I was using.
How can I pass an equation symbol (such as + – * /) as a variable?
I am starting with collecting user input with something like this below. So the input sets the equation type chosen. Then sends the information as variable to the class
I wanted to be able to do this without just writing a bunch of if/elif statements and just send a singular variable.
if selection == '1':
selection = "+"
print("You chose Addition")
MathTime.math(selection)
Then in the MathTime
class it would do something like this below
Yes, I know I didnt show all code, for how I am gathering the x/y (other user input) not important for this. Just wanted to keep it minimal for the example to be understandable and easy.
z = float(x) equation float(y)
print(f"{x} + {y} = {z}")