In this assignment we will build a simple calculator that performs binary operations between two numbers.
Create a calculator that:
Here's an example of what it might look like for the calculator to run twice. The first time the user enters "add" and then "17" and "23".
Menu:
- add
- subtract
- multiply
- divide
- quit
Choose an option: add
Enter a first number: 17
Enter a second number: 23
Output: 17 + 23 = 40
In this second example, the user enters an invalid choice, "exponent" and an error message is displayed and the Menue is displayed again.
Menu:
- add
- subtract
- multiply
- divide
- quit
Choose an option: exponent
Error: exponent is not an option
Menu:
- add
- subtract
- multiply
- divide
- quit
Choose an option: quit
Goodbye!
This calculator should validate that the option that was select is correct and keep providing the menue until it is.
Do the above FIRST before attempting anythinge below.
mod
(%
) and exponent
(**
) as options.Only attempt this after you've done all of the above.
+
, -
, /
, *
, **
, or %
, then another number and it imemdiately calculates the result.quit
support clear
so that the user can undo their first number entry.Example of this all together:
Input: 7
Output: 7
Input: +
Output: 7
Input: 7
Output: 14
Input: +
Output: 7
Input: 6
Output: 18
Input: clear
Output: 0
Input: -
Output: 0
Input: 15
Output: -15
while True:
print("Menu:")
print("- add")
print("- subtract")
print("- multiply")
print("- divide")
print("- quit")
choice = input("Choose an option: ")
if choice == "quit":
print("Goodbye!")
break
first_value = float(input("Enter the first number: "))
second_value = float(input("Enter the second number: "))