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
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
Get Answers For Free
Most questions answered within 1 hours.