I have a problem to run this Calculator!

Please see the attached image to Know my Code. I just want to make a calculation (+ - * /) from User input. But the code is not working, I think there is something wrong. I would be grateful if someone helps me to solve this problem!

Screenshot_1

I think there’s no need to make the operators strings

When you take user input, you get a string… so number_1 is a string. I’m pretty sure this is the reason your calculator is not working.

You can verify that number_1 is a string by printing:

print(type(number_1))

For the calculator to work you have to convert number_1 (and number_2) to an integer, do the math and then concatenate to give the result back to the user. However, consider that you can only concatenate strings… so maybe you need to convert the result to a string again :roll_eyes:… or keep it simple and use python formater to avoid converting:

https://www.w3schools.com/python/ref_string_format.asp

Let me know how the calculator ends up!

1 Like

you need to convert the answers for numbers to integer or float:

number1 = float(input(‘first num’))

operator = input(‘operator’)

number2 = float(input(‘second num’))

1 Like