Question

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 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

Homework Answers

Answer #1

PYTHON PROGRAM

# userInput function
def userInput():
#reads the input from user
num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
lst = []
# user input appending to a lst
lst.append(num1)
lst.append(num2)
# returns the user input in the form of list
return lst
# add function
def add(lst):
res = lst[0]+lst[1]
# returns the addition
return res
# substract function
def substract(lst):
res = int(lst[0])-int(lst[1])
# returns the substract result
return res
# multiply function
def multiply(lst):
res = lst[0]*lst[1]
# returns the multiply
return res
# divide function
def divide(lst):
res = lst[0]/lst[1]
# returns the divide
return res
# modulo function
def modulo(lst):
res = lst[0]%lst[1]
return res
# exponent function
def exponent(lst):
res = pow(lst[0],lst[1])
return res
# userOutput function
def userOutput(lst):
print()
# prints the all calculations
for i in range(len(lst)):
print(lst[i])

# main function which calls the all modules
# in a main function retunred value of a modules is stored in list that is "lt"
def main():
lt = []
# calling the function userInput function
lst = userInput()
# calling the add function
ret = add(lst)
# retunred value of add function appending to lt list
lt.append(ret)
ret = substract(lst)
lt.append(ret)
ret = multiply(lst)
lt.append(ret)
ret = divide(lst)
lt.append(ret)
ret = modulo(lst)
lt.append(ret)
ret = exponent(lst)
lt.append(ret)
#passing the list to userOutput
userOutput(lt)

if __name__=="__main__":
# calling a main function
main()
  

OUTPUT

TRY TO TYPE THE CODE

BEAWARE OF INDENTATION

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
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS OR SWITCH STATEMENTS IN THE JAVASCRIPT. Even though there is stylesheet in the HTML file do no create a new one. Project Standards: Students will use click events to capture user input. Students will use variables to store information needed by their application and keep track of their program’s state. Students will use conditionals to control project flow. Project Task You will be building...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT