Question

In: Computer Science

Create a Python file num_utils.py that includes: A function sum_of_nums that accepts 1 or more number...

Create a Python file num_utils.py that includes:

  • A function sum_of_nums that accepts 1 or more number parameters and returns their sum without displaying anything
  • A function product_of_nums that accepts 1 or more number  parameters and returns their product without displaying anything
  • A function average_of_nums  that accepts 1 or more number  parameters and returns their average without displaying anything

Create a Python file test_num_utils.py that:

  • Imports num_utils
  • Defines a function test_num_utils that demonstrates the use of the utilities in num_utils.py
  • Executes test_num_utils

Solutions

Expert Solution

Given below is the code for the question. Ensure to indent as shown in image. Please do rate the answer if it helped. Thank you.

num_utils.py
----
def sum_of_nums(*nums):
   s = 0
   for n in nums:
       s = s + n
   return s


def product_of_nums(*nums):
   prod = 1
   for n in nums:
       prod = prod * n
   return prod
  


def average_of_nums(*nums):
   n = len(nums)
   return sum_of_nums(*nums) / n


--------------
test_num_utils.py
--------------
import num_utils as nu

def test_num_utils():
print('Testing with 1 argument 5')
print('sum = ', nu.sum_of_nums(5))
print('product = ', nu.product_of_nums(5))
print('average = ', nu.average_of_nums(5))


print('Testing with 3 argument 2, 4, 6')
print('sum = ', nu.sum_of_nums(2, 4, 6))
print('product = ', nu.product_of_nums(2, 4, 6))
print('average = ', nu.average_of_nums(2, 4, 6))

test_num_utils()

output


Related Solutions

On Python Write a function that accepts a relative file path as parameter and returns number...
On Python Write a function that accepts a relative file path as parameter and returns number of non-empty lines in the file. Test your function with the provided sample file studentdata.txt.
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on the command line 2. For each file name provided, delete any line that contains the string: qwe.rty When the changes are completed, the script should display the total number of files scanned, and the total number of files changed. Example Command: assessment-script-a file.a file.b file.c file.d file.e    Example Output: 5 files scanned, 3 files changed 3. Your script should include a series of...
PYTHON. Create a function that accepts a filename where in each line there is a name...
PYTHON. Create a function that accepts a filename where in each line there is a name of a type of bird. use a python dictionary in order to count the # of time each bird appears. (1 line = 1 appearance) Loop over your dict. to print each species and the # of times it was seen in the file once all lines have been counted. return dictionary containing count the filename opens this: blackbird canary hummingbird canary hummingbird canary...
Create a Python file named num_sum.py that contains: The definition of two functions: volume - accepts...
Create a Python file named num_sum.py that contains: The definition of two functions: volume - accepts three parameters and returns the product of them, but displays nothing sum_of_nums - accepts 1 or more numbers and returns their sum, but displays nothing A print function call that includes a call to volume, passing 2, 3, and 4 A print function call that includes a call to sum_of_nums, passing 1, 2, 3, 4, and 5
Write a function file that accepts each of the four vectors as inputs. The function file...
Write a function file that accepts each of the four vectors as inputs. The function file should plot the data on different graphs in the same window. You need to add axis labels and graph titles. time- 0 5 10 15 20 25 30 A1- 0 7 11 19 15 14 7 A2- 0 10 15 21 16 11 13 A3- 0 9 13 17 22 25 21
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
Create your own function in C that accepts one input number and returns a double number....
Create your own function in C that accepts one input number and returns a double number. The themes for the functions should be one of the following: Calculates 3.14 times of the square of input number. For example, if 2 is input then 12.56 should be returned. (e.g. 3.14*2*2 = 12.56)
Create your own function in C that accepts one input number and returns a double number....
Create your own function in C that accepts one input number and returns a double number. The themes for the functions should be one of the following: Divides the number by 3 and returns the result. For example, if 6 was input then 2.0 should be returned. provide both your C code and an example call to the C code function. Be sure to provide an overview of what your function is doing. Include header documentation in the code as...
USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts...
USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts a Date object dateStr and returns a string that is the day of the week in English form (i.e. “Sunday”, “Monday”, etc.). Test your function by creating a date object that is a significant date to you (such as your birthday) and passing that date object to your function. Test your function at least twice with two different dates. Submit the dayOfWeek.js file to...
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT