Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago