Question

Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs none then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a check if the denominator is a 0. If it is 0, then print a message that- denominator cannot be 0 while performing a division operation
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Python implementation of the code :

while(True):

op = input('''
Please type in the math operation you would like to complete:
+ for addition
- for subtraction
* for multiplication
/ for division
none for termination
''')


if op == "+":
a = int(input("enter numbr 1 "))
b = int(input("enter number 2 "))
print("{} + {} = {}".format(a,b,a+b))
elif op == "-":
a = int(input("enter numbr 1 "))
b = int(input("enter number 2 "))
print("{} + {} = {}".format(a,b,a-b))
elif op == "*":
a = int(input("enter numbr 1 "))
b = int(input("enter number 2 "))
print("{} + {} = {}".format(a,b,a*b))
elif op == "/":
a = int(input("enter numbr 1 "))
b = int(input("enter number 2 "))
if b == 0:
print("denominator cannot be zero")
continue
print("{} + {} = {}".format(a,b,a/b))
elif op =="none":
break
else:
print("Use only +, -, *, / operators")
pass

Add a comment
Know the answer?
Add Answer to:
Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Write a program which gets user choice for addition, subtraction, multiplication and division with characters ’+’,...

    Write a program which gets user choice for addition, subtraction, multiplication and division with characters ’+’, ’-’, ’*’, and ’/’ respectively. This program should keep asking for two numbers and a choice to perform such operations inside a loop which can be only stopped by entering ’q’. I've been working out of code blocks and now I'm not sure how to go about this iew Search Project Build Debug Fortran wwSmith Tools Tools+ Plugins DoxyBlocks Settings Help maino: int -NM...

  • Implement a simple four function calculator in the LC3 assembly language that will run on the...

    Implement a simple four function calculator in the LC3 assembly language that will run on the LC-3 simulator. The LC-3 computer only reads a character at a time but is capable of displaying a string of characters. This calculator program will use multiple subroutines that perform purposes such as reading multi-digit numbers, converting them to integers, performing addition, subtraction, multiplication, or division on these numbers, and displaying the result. The inputs to the calculator will not exceed 4 digits. The...

  • In this lab you will code a simple calculator. It need not be anything overly fancy,...

    In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in three small sections. You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction Multiplication, and Division), and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic operations...

  • Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int...

    Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int = 0, int = 1 ); // default constructor Rational addition( const Rational & ) const; // function addition Rational subtraction( const Rational & ) const; // function subtraction Rational multiplication( const Rational & ) const; // function multi. Rational division( const Rational & ) const; // function division void printRational () const; // print rational format void printRationalAsDouble() const; // print rational as...

  • C# ONLY C# ONLY C# ONLY In this assignment you will implement the undo feature for a simple calculator. The undo feature...

    C# ONLY C# ONLY C# ONLY In this assignment you will implement the undo feature for a simple calculator. The undo feature must be implemented using a generic or template-based Stack data structure. You may utilize language supplied libraries (e.g. java.util.stack) or a stack implementation of your own design. No third-party downloads or software installs are allowed. The undo feature must allow for an unlimited number of undo operations. If the user attempts to perform an undo operation and the...

  • C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use...

    C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use functions. Use a custom library and namespace. Use reference variables as parameters to return values from functions. Create a robust user interface with input error checking. Use exceptions to indicate errors. Resources kishio.h kishio.cpp Assignment requirements You will need eight methods (including main). One is given to you. Their requirements are specified below: menu: The menu function takes no arguments, but returns a char...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT