Question

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 flowchart and pseudocode forms for the following two functions:

A. Write a Python function that receives a real number argument representing the sales amount for videos rented so far this month. The function asks the user for the number of videos rented today and returns the updated sales figure to the main function. All videos rent for $4.25.

B. Write a Python function that receives three integer arguments and returns the maximum of the three values.

3) Create the algorithm in both flowchart and pseudocode forms for a main program that tests the two above functions.

C. Write a Python main program that calls both above functions to shows that both functions work properly.

Programming Notes:

Function Definition -- def functionName( parameter list )

receives -- this denotes a value that is passed to the function as a parameter.

ask the user -- this denotes a value that the functions requests of the user.

return -- this denotes a value that is returned from the function to the calling program.

program including both functions and the main program in one python source file.

Answer #1

'''

Python version : 3.6

Python program to create and test 2 functions

'''

def calculateSales(amount):

'''

Function that receives a real number argument
representing the sales amount for videos rented so far this
month

The function asks the user for the number of videos
rented today and returns the updated sales figure to the main
function.

All videos rent for $4.25.

'''

# input the number of videos rented today

rented = int(input('Enter the number of videos rented
today: '))

# return the updated sales

return(amount + (rented*4.25))

def maximum(value1, value2, value3):

'''

Function that receives three integer arguments and
returns the maximum of the three values.

'''

# set max_value to value1

max_value = value1

# if value2 > max_value, update max_value to
value2

if value2 > max_value:

max_value = value2

# if value3 > max_value, update max_value to
value3

if value3 > max_value:

max_value = value3

return max_value

# test the functions

sales = calculateSales(0)

print('Updated sales: %.2f' %sales)

sales = calculateSales(sales)

print('Updated sales: %.2f' %sales)

print('Maximum of 35, 70, 55: %d'
%(maximum(35,70,55)))

#end of program

**Code Screenshot:**

**Output:**

Write a function that takes two integer inputs and returns the
sum of all even numbers between these inputs, and another function
that takes two integer inputs and returns the sum of odd numbers
between these inputs .In main function, the program will asks the
user to enter two integer numbers and then passes them to these two
functions and display the result of each of them.
[0.5 mark] (BY
USING C PROGRAM)

TO BE DONE IN PYTHON: Write a function `lowest_integer()` which
takes 2 input arguments:
1)a function `g` representing an increasing function
g(x)
2) a number `gmin`,
and returns an integer `nmin` such that
nmin>0
is the smallest integer that satisfies
g(nmin)>gmin.
test:
def g(n):
return 2*n
print(lowest_integer(g, 10))
Output: 6

IN PYTHON : Write a program that asks the user for a number.
Write the number to a file called total.txt. Then ask the user for
a second number. Write the new number on line 2 with the total for
both numbers next to it separated by a comma. Then ask the user for
a third number and do the same. Keep asking for numbers until the
person puts in a zero to terminate the program. Close the file. Be...

Write the functions which are called in the main function
given.
YOU MAY ASSUME THAT THE USER ENTERS A VALID INTEGER.
printDouble should accept one value and should print the value
of that number times 2.
printEndMessage should not accept any values and should print a
message indicating that the program has finished.
def main():
num1 = int(input("Please enter your number "))
printDouble(num1)
printEndMessage()
main()

1. Write a function called compute_discount which takes a float
as the cost and a Boolean value to indicate membership. If the
customer is a member, give him/her a 10% discount. If the customer
is not a member, she/he will not receive a discount. Give all
customers a 5% discount, since it is Cyber Tuesday. Return the
discounted cost. Do not prompt the user for input or print within
the compute_discount function. Call the function from within main()
and pass...

Here are the function prototypes
for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four
functions work The user should be able to provide four values to
your program (three floats and an int) Your program should then
use your four new functions and also display the results to the
user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of
three floatsfloat mean( float...

Please write the code
in Python.
Write a
program/function in any Object-Oriented programming language that
will implement Queue Abstract Data Type with the following
functions/methods. Any build-in/pre-defined Queue
function/library (e.g., java.util.Queue in Java) is
NOT allowed to use in your code.
push(Element): insert the
input Element (e.g., String or Integer in Java) to the end
of the queue.
pop(): remove
the head element of the queue and print the head element on
screen.
count(): return the total number of
elements in the queue...

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

Python
Problem 1
Create a function, biggest_ip_sum, outside of the ServerClass
class, that:
1. Takes two ServerClass objects
2. Sums the octets of the IP together (example 127.0.0.1 =
127+0+0+1 = 128)
3. Returns the larger number
Example:
server_one = ServerClass("127.0.0.1")
server_two = ServerClass("192.168.0.1")
result = biggest_ip_sum(server_one, server_two)
print(result)
In the example above, result will be 361.
_________________________________
Problem 1 Here is the code to start with
class ServerClass:
""" Server class for representing and manipulating servers. """
def __init__(self,...

In C++
Employee Class
Write a class named Employee (see definition below), create an
array of Employee objects, and process the array using three
functions.
In main create an array of 100 Employee objects using the
default constructor.
The program will repeatedly execute four menu items selected by
the user, in main:
1) in a function, store in the array of Employee objects the
user-entered data shown below (but program to allow an unknown
number of objects to be stored,...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 2 minutes ago

asked 6 minutes ago

asked 9 minutes ago

asked 10 minutes ago

asked 11 minutes ago

asked 13 minutes ago

asked 18 minutes ago

asked 20 minutes ago

asked 33 minutes ago

asked 43 minutes ago

asked 48 minutes ago

asked 48 minutes ago