Question

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

Homework Answers

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:

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
Write a function that takes two integer inputs and returns the sum of all even numbers...
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)
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
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
Question 1 Write functions that do the following: i) A function that takes 2 arguments and...
Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are...
IN PYTHON : Write a program that asks the user for a number. Write the number...
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...
Create a Python main program which calls two functions enterNum and calcResult and accomplishes the following:...
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...
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...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 YOU WILL NEED THREE FUNCTIONS: the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) Call the functions and passing the arguments in the "main" function. Example: def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) main() ----- Testing the outputs of your code: 1 for the valid...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE...
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()
Write a program that asks the user to enter two integer numbers. the main function then...
Write a program that asks the user to enter two integer numbers. the main function then passes these numbers to a function named exp that calculates the multiplication of these numbers and print the exponential value of the result of multiplication
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT