0

Python calculator

I am to create a calculator that takes 2 floats as input and performs arithmetic operations on them. Also, there has to be a case when there's zero division. I run: x = float(input()) y = input() z = float(input()) if y == '/' and z != 0: print(x / z) elif y == '/' and z == 0: print("Zero division") if y == '%': print(x % z) if y == '**': print(x ** z) if y == '//': print(x // z) if y == '*': print(x * z) if y == '-': print(x - z) if y == '+': print(x + z) And get: Failed test #1. Runtime error Traceback (most recent call last): File "jailed_code", line 3, in <module> z = float(input()) ValueError: could not convert string to float: 'mod' What's wrong with the code?

4th Jul 2019, 10:58 AM
John Galt
John Galt - avatar
2 Respostas
+ 1
I tried your code in CodePlayground and it worked fine - what did you input?
4th Jul 2019, 11:05 AM
Rincewind
Rincewind - avatar
+ 1
I've inputted all the ops I had enumerated and in PyCharm it works too. But for some reason the website of the course I'm taking spits out an error. xd Anyway, thanks.
4th Jul 2019, 11:07 AM
John Galt
John Galt - avatar