Question

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

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

Create a Python main program which
calls two functions enterNum and calcResult and accomplishes the
following:
1. The main program calls the function enterNum 3 times. The
first time enterNum is called, the main program stores the returned
output in the variable xx. The second time, the returned output is
stored in the variable yy and the third time in zz.
2. enterNum asks the user to enter a floating point number. This
function has no input arguments and returns...

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

Write the following ANNA assembly language programs.
1.HighestnumberWrite an ANNA assembly program (high.ac) that
will continuously prompt the user for numbers. When the user enters
a negative number, print the highest positive number entered by the
user and exit the program. Print a zero if they did not enter any
positive numbers.
2.DivisionWrite an ANNA assembly program (div.ac) that divides
two positive numbers that come from user input and returns both the
quotient and the remainder. For example, if the...

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

1.
Write a complete program in C++ that does the following:
[2] asks a user to enter two integer numbers
(display a warning message that the second number should be
different from zero)
[3] reads the two numbers from the
keyboard;
[4] displays the product, the sum, the quotient
and the remainder of integer division of the first one by the
second one.
[3] displays the result of floating-point
division.
Make sure to follow programming style guidelines.

In Python write a program that prompts the user for six elements
and their atomic numbers and stores them in a list. Each element
and weight pair should also be a list. After the values have been
entered, print the list as it entered. Then print the first two
characters from the element names (the first character capitalized
and the second in lower case) along with the atomic number,
starting with the element with the lowest atomic number. You
must...

Dice Game – Accumulator Pattern and Conditionals (40
pts) IN PYTHON
Write a program dicegame.py that has
the following functions in the following order: in python
Write a function roll that takes an int n and returns a random
number between 1 and n inclusive. Note: This function represents a
n sided die so it should produce pseudo random numbers. You can
accomplish this using the random module built into python.
(3 pts)
Write a function scoreRound that...

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

##4. What will the following program display?
##def main():
## x = 1
## y = 3.4
## print(x, y) ## first printing
## change_us(x, y)
## print(x, y) ##second printing
##
##def change_us(a, b):
## a = 0
## b = 0
## print(a, b)
##
##main()
##
##Yes, yes, main() displays
##1 3.4
##0 0
##1 3.4
## The question is: why x and y are still the same while the
second printing of
(x,y)?
## It seems...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 4 minutes ago

asked 7 minutes ago

asked 7 minutes ago

asked 13 minutes ago

asked 19 minutes ago

asked 30 minutes ago

asked 38 minutes ago

asked 53 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago