Question

Write a python program that functions as a calculator. The program should run in an infinite...

Write a python program that functions as a calculator. The program should run in an infinite loop. It should ask the user for two numbers and then offer four choices:

1) Add

2) Subtract

3) Multiply

4) Divide

Once it gets the operation from the user, it should call one of four functions to perform the operation and display the result. The functions should be placed in another module called calc.py

Homework Answers

Answer #1

def Add(a,b):
return (a+b)
def Sub(a,b):
return (a-b)
def Mul(a,b):
return (a*b)
def Div(a,b):
return (a/b)
while(1):
a=int(input("Enter ist no. "))
b=int(input("Enter 2nd no. "))
print("1) Add")
print("2) Subtract")
print("3) Multiply")
print("4) Divide")
ch=int(input("Enter the choice to perform operation: "))
if(ch==1):
print("Addition of no. is :",Add(a,b))
elif(ch==2):
print("Subtraction of no. is :",Sub(a,b))
elif(ch==3):
print("Multiplication of no. is :",Mul(a,b))
elif(ch==4):
print("Division of no. is :",Div(a,b))
else:
print("Invalid choice")

Know the answer?
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
Similar Questions
Write a phython program to display a menu with the following options: (1) add, (2) subtract,...
Write a phython program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. If the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
Answer must be submitted in a python file (.py at the end of the file) You...
Answer must be submitted in a python file (.py at the end of the file) You will ask three questions (1-3 below). Based on the answer from question 3, you will determine to add, subtract, divide or multiply question 1 and 2. Enter value one? Enter value two? What operation would you like to perform? 1 to add, 2 to subtract, 3 to divide and 4 to multiply. Print the result Make sure to cover all four scenarios from question...
I would like you to do is create a console application that will either add, subtract...
I would like you to do is create a console application that will either add, subtract or divide two numbers. The Program will have four functions one to add, subtract, multiply and divide the two numbers. The user will enter the two number and the +, -, *, / symbol and the program will display the appropriate result.
Create a new class called Calculator. A calculator should be able to add, subtract, multiply, divide...
Create a new class called Calculator. A calculator should be able to add, subtract, multiply, divide and clear. Test your calculator by writing a main program incorporating the test code below: Calculator mycalc; mycalc.clear(); mycalc.add(4.52); mycalc.add(3.789); mycalc.divide(2.6); mycalc.multiply(3.12); mycalc.subtract(2.678); cout << mycalc.display() << endl;       // prints out "7.2928" mycalc.clear(); mycalc.add(5.0); cout << mycalc.display() << endl;       // prints out "5" //advanced stuff #1: add a constructor Calculator calc1; cout << calc1.display() << endl;  //prints out 0 //advanced stuff #2: add a parameterized...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
This python program must have 9 functions: •main() Controls the flow of the program (calls the...
This python program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers, returns the modulo of the...
Write a PYTHON program that displays a weekly payroll report. A loop in the program should...
Write a PYTHON program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: ▪ Do not accept negative numbers for any of the items entered....
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Using Python: Write a program which includes functions to calculate the area, perimeter and diameter of...
Using Python: Write a program which includes functions to calculate the area, perimeter and diameter of a circle. You should have a functions compute_area(), compute_perimeter() and compute_diameter(). In addition, you should have a main() function. Your main function should ask the user for the radius of a circle, then ask the user if they would like to compute the area, the perimeter or the diameter. The user should enter "A" for area, "P" for perimeter and "D" for diameter. Your...