Question: Write a python program that is a simple calculator supporting five operations. Addition, subtraction, multiplication, division, and square. The interaction is as below. 1. The
Write a python program that is a simple calculator supporting five operations. Addition, subtraction, multiplication, division, and square. The interaction is as below.
1. The program initially displays the following text. This is a simple calculator that supports
addition, subtraction, multiplication, division, and square
Enter:
a to add,
s to subtract,
m to multiply,
d to divide,
q to square
and prompts for a command by displaying the line
Enter command:
2. The user then enters one of the five letters (a, s, m, d, q).
3. Depending on the command, the program prompts for and reads in one or two numbers. (For square, only one number is read in; for all other valid commands, the program reads in two numbers.) The numbers are integers.
4. If the command is not valid, the program displays an error message and terminates.
5. For all valid commands, the program computes the answer and displays the result.
6. The program then ends.
The program must not prompt for anything that is not called for by the above list or the interactions given later. Make sure that the program prompts for the input and displays the result as specified. Debug your code as necessary until it complies with all requirements. The Python code should prompt for user input and display results as given in the six sample interactions below. There are six invocations of the program, and they are separated by blank lines. This is a simple calculator that supports
addition, subtraction, multiplication, division, and square
Enter:
a to add,
s to subtract,
m to multiply,
d to divide, q to square
Enter command: a
Enter the first number: 3
Enter the second number: 4
The sum is 7 This is a simple calculator that supports addition, subtraction, multiplication, division, and square
Enter: a to add,
s to subtract,
m to multiply,
d to divide,
q to square
Enter command: s
Enter the first number: 6
Enter the second number: 2
The difference is 4 This is a simple calculator that supports addition, subtraction, multiplication, division, and square
Enter:
a to add,
s to subtract,
m to multiply,
d to divide,
q to square
Enter command: m
Enter the first number: 2
Enter the second number: 3
The product is 6 This is a simple calculator that supports addition, subtraction, multiplication, division, and square
Enter:
a to add,
s to subtract,
m to multiply,
d to divide,
q to square
Enter command: r
Invalid choice
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
