Question

In: Computer Science

python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow...

python code

Write a simple calculator:

This 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 first number divided by the second number

•exponent() Accepts two numbers, returns the first number raised to the power of the second number.

•userOutput() Gives a user friendly output of all the calculations.

NOTE: The ONLY place that you will print results is inside the userOutput function

with any numbers entered. Your program must print an appropriate message if the user enters anything other than two integers. (Hint: Try...except)

Solutions

Expert Solution

from math import *
def main():
a,b=userInput()
r=add(a,b)
userOutput(r,"addition")#call the methods and print the results
r=subtract(a,b)
userOutput(r,"subtract")
r=multiply(a,b)
userOutput(r,"multiply")
r=divide(a,b)
userOutput(r,"divide")
r=modulo(a,b)
userOutput(r,"modulo")
r=exponent(a,b)
userOutput(r,"exponent")
  
  
def userInput():
try:
n1=int(input("Enter number 1:"))
n2=int(input("Enter number 2:"))#read numbers
except:
print("Enter valid numbers")
return n1,n2#return numbers
  
def add(a,b):#functions that compute result and return the values to main function
return a+b
  
def subtract(a,b):
return a-b
  
def multiply(a,b):
return a*b
  
def divide(a,b):
return a/b
  
def modulo(a,b):
return a%b
  
def exponent(a,b):
return pow(a,b)
  
def userOutput(res,op):#prints the output result to the user
print("The ",op," result of two numbers is ",res)
main()#call the main function

Screenshots:

The screenshots are attached below for reference.

Please follow them for output and proper indentation.

Please upvote my answer. Thank you.


Related Solutions

This program must have 9 functions: •main() Controls the flow of the program (calls the other...
This 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 first...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Write an IPO diagram and Python program that has two functions, main and determine_grade. main –...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main – Should accept input of five numeric grades from the user USING A LOOP.   It should then calculate the average numeric grade.    The numeric average should be passed to the determine_grade function. determine_grade – should display the letter grade to the user based on the numeric average:        Greater than 90: A 80-89:                 B 70-79:                 C 60-69:              D Below 60:           F Modularity:...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”....
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”. It takes one or more files and displays requested number of lines from the ending. If number is not specified, then it print 10 lines by default.
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
Write a program in c++, with at least four functions, including main, which must do the...
Write a program in c++, with at least four functions, including main, which must do the following: Ask user whether they want to encode or decode a message – if no, then terminate Take the input string from the user, store it in dynamic memory (use new) As appropriate, encode or decode the message using Rot13. Output the encoded/decoded message Delete the input string from dynamic memory (use delete) Input will be a string of no more than 25 characters....
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT