What I need is, am I doing correct? If not where to look at this to solve this problem.
CS50 Python Math Interpreter problem by converting user input to make a simple case-sensitive calculator.It is case-sensitive because I want to use .split(" ") to store the inputs seperatly so I can use them later in the code.
It is suggested in the probelm to use 'x, y, z = expression.split(" ")'Let user enter an expression
- x and z is an integer
- y is a +, -, *, or /Should have one floating point 00.0For excample if the user inputs 1 + 1, your program should output 2.0. Assume that, if y is /, then z will not be 0.
I first tried this one, but I'm not sure even I'm doing the correct thing by using .format()
simp_arithmetic = input("Expression: ")x, y, z = simp_arithmetic.split(" ")if '+' in simp_arithmetic: print(simp_arithmetic.format(x + z))elif '-' in simp_arithmetic: print(simp_arithmetic.format(x - z))elif '*' in simp_arithmetic: print(simp_arithmetic.format(x * z))elif '/' in simp_arithmetic: if z == '0': print("z can't be 0") else: print(simp_arithmetic.format(x / z))else: print(" ")
After this, I changed the format()print(simp_arithmetic.format(int(x) + int(z))),
orprint(simp_arithmetic.format(int:x + int:z))
And I was expeting a out come like 1 + 1 = 2.0 or similar to this but my program only returns the given value in addition.