Task 1 - Creating and Calling Functions#
1.1 - Average of a list#
Write a Python function that returns the average of a list of values, and then test it with a variety of inputs.
Restriction: I want you to write the average function yourself (from scratch), you cannot use np.mean()
, mean()
, or any other average function.
Hint: Remember the mean of a function is just the sum of all the values, divided by the number of values in the list.
Requirements:
Create function with name
avglist
that accepts three parameters:lst
- list of numbers (required parameter)low
- miminum value (not inclusive). (optional parameter, default = 0)high
- maximum value (not inclusive). (optional parameter default = 100)
Your function will calculate and return only the average of values in the range (
low
,high
).Your function should have a docstring.
Call
help(avglist)
to display function information.Create a list with the numbers 1 to 10 and call
avglist()
with default range and print the result.Create a list with the numbers 1 to 100 and call
avglist()
with range (20
,80
) and print result.Create a list with 100 random numbers between 1 and 100 and call avglist() with range (
30
,100
) and print the result. Note: Will need toimport random
and userandom.randint(1,100)
.
Reminder: To set the seed, use random.seed(100)
.
Sample Output#
For this question, no sample input is provided.
# add your import statements here
# Your solution here