Skip to content
← Back to Community
The Second Calculator
Profile icon
gatorade322

This is the second version of my calculator

This is a second version of the calculator that I posted before. I know people were having problems, so I came up with an easier to use calculator. Here is the code you will need:

running = True while running: num1 = input() operator = input() num2 = input() if operator == "+" or operator == "plus": answer = float(num1) + float(num2) if operator == "-" or operator == "minus": answer = float(num1) - flaot(num2) if operator == "*" or operator == "x" or operator == "X" or operator == "times": answer = float(num1) * float(num2) if operator == "\" or operator == "/" or operator == "diveded by": answer = float(num1) / float(num2) if operator == "quit": running = False print(operator)

this, I tested in a repl. If there are any errors, please say them in the comments. It's possible I may have imported a typo. This should work, and I also aloud the possible quit, if you wanted to leave.

Voters
Profile icon
gatorade322
Comments
hotnewtop
Profile icon
CodeLongAndPros

Spelling alert!

diveded

Escape alert!

Division should be:

if operator == "\\" or operator == "/" or operator == "diveded by":
Profile icon
gatorade322

@CodeLongAndPros yep, but there aren't two 's there

Profile icon
CodeLongAndPros

@gatorade322 You need to escape the backslash. Add syntax highlighting to your code block. (```python)

Profile icon
gatorade322

@CodeLongAndPros OH OK, how to do that?