Implement in python a function avg_val(lst), which returns the
average
value of the elements in list.
For example, given a list lst: [19, 2, 20, 1, 0, 18], the
function
should return 10.
The name of the method should be avg_val and the method should take
one parameter which is the list of values to test. Here is an
example call to the function
print(avg_val([19, 2, 20, 1, 0, 18]))
Solution:-
Python 3 Code:-
# Function computing average of elements in the list
def avg_val(lst):
# computing total sum of the elements in the list
total_sum = sum(lst)
# computing total number of the elements in the list
length = len(lst)
# computing average
average = total_sum / length
return average
# Test case
print(avg_val([19,2,20,1,0,18]))
Code snapshot:-
Output snapshot:-
Get Answers For Free
Most questions answered within 1 hours.