CJCoding With Joseph
15free / daySign inCreate account

Text Calculator

Write a text calculator that loops until the user quits. Each pass reads an operator with the prompt Operator (+ - * / or q): , stripped. The letter q prints Goodbye! and leaves the loop. Anything other than +, -, * or / prints Unknown operator. and the loop simply comes round again (no numbers are read). A valid operator then reads two numbers with the prompts First: and Second: , converted with float(), and prints Result: <value> with two decimals (:.2f); dividing when the second number is 0 prints Cannot divide by zero. instead. Input: one line per operator or number, ending with q. Prompts are part of the output, so the two number prompts and the result share a line with the operator prompt.

Expected Output:

Operator (+ - * / or q): First: Second: Result: 5.00
Operator (+ - * / or q): First: Second: Result: 3.50
Operator (+ - * / or q): Goodbye!

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Menus & ValidationOperators
📥 Auto-Input:
+\n2\n3\n/\n7\n2\nq\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.