Question
Write a program (Python script) named mycalc, which implements a simple calculator using python. As you approach this assignment try to visualize how you would
Write a program (Python script) named mycalc, which implements a simple calculator using python. As you approach this assignment try to visualize how you would use a calculator. Typically you would enter a number into the calculator, next you would select an operation to perform (add, subtract, multiply, divide), next you would enter a second number, finally you would press the equals sign to display the result. The following examples illustrate both a flowchart and the pseudo code that outlines how to solve the calculator problem. They provide a conceptual model of the calculator. A conceptual model is something that attempts to describe how a program works. It also defines how the program must flow from one task or statement to the next, and describes the functionality that the program will provide. Remember that division by zero is not defined in mathematics, so it will be necessary for the program to check the value entered by the user to assure that the value entered is not zero. It is always a good idea to check user input to make sure the input is the type of data our program is expecting. How would the program react if the user input something other than addition, subtraction, multiplication or division when prompted? Obviously, user input validation is an important part of programming and you should demonstrate user input validation in this program. You should submit a script file (.txt is preferred) and an output file (.doc or .pdf). Multiple file uploads is permitted. Dont forget to use comments and readable variable names. Pseudo Code for Python Calculator Prompt for first number Read first number and store in variable While first number is equal to 0 Display error Prompt for first number Read first number and store in variable Display operations (1-add, 2-subtract, 3-multiply, 4-divide) Prompt for operation Read operation and store in variable While operation is less than 1 or operation is greater than 4 Display error Prompt for operation Read operation and store in variable Prompt for second number Read second number and store in variable While second number is equal to 0 Display error Prompt for second number Read second number and store in variable If operation is equal to 1 (add) Then Add first number to second number and store result in variable Otherwise if operation is equal to 2 (subtract) Then Subtract second number from first number and store result in a variable Otherwise if operation is equal to 3 (multiply) Then Multiply first number with second number and store result in a variable Other wise if operation is equal to 4 (divide) Otherwise (divide) Divide first number by the second number and store result in a variable Display the result stored in the variable Exit the program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started