Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am suppose to do a test using the range and I'm pretty sure what I have is correct but I am getting the following

I am suppose to do a test using the range and I'm pretty sure what I have is correct but I am getting the following error

AttributeError: module 'func' has no attribute 'c'

Below is the testing code and the code with the function

import introcs import func

def test_avg(): """ Test procedure for function avg(). """ print('Testing avg()') result = func.c introcs.assert_floats_equal(0,result) result = func.avg(7, 1, 4, 3, 6, 8) introcs.assert_floats_equal(4.833333333333333,result) result = func.avg(-1, 1, 3, 5) introcs.assert_floats_equal(2.0,result) result = func.avg(2.5) introcs.assert_floats_equal(2.5,result) result = func.avg(1.0, 1.0, 1.0) introcs.assert_floats_equal(1.0,result) # Test range(10,20) here tupRange = range(10,20) arg = tuple(tupRange) result = func.avg(*arg) introcs.assert_floats_equal(14.5,result)

if __name__ == '__main__': test_avg() print('Module func passed all tests.')

This is below is func

def avg(*args): # The parameter is MISSING. Add it back. """ Returns average of all of arguments (passed via tuple expansion) Remember that the average of a list of arguments is the sum of all of the elements divided by the number of elements. Examples: avg(1.0, 2.0, 3.0) returns 2.0 avg(1.0, 1.0, 3.0, 5.0) returns 2.5 avg(1.0, 2.0, 3.0) returns 0 Parameter args: the function arguments Precondition: args are all numbers (int or float) """ vals = 0 if args == (): return 0 for value in args: vals = vals + value mean = vals / len(args) return mean

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

Students also viewed these Databases questions

Question

4. Show the trainees how to do it again.

Answered: 1 week ago