71.4k views
3 votes
Modules & Functions: Define the following functions in a module called funcbundle: get_average(data): takes a list of integer values and returns the average value. get_min(data): takes a list of integers and returns the smallest value. get_below_avg_count(data): takes a list of integers and returns the count of values below average. In the main file, write code in the main function to prompt the user for 10 integer values, store them in a list and then call the above functions with the list as an argument and print the results with proper messages describing the values. All output is done in the main function. python language.

1 Answer

3 votes

Final answer:

The question involves creating a Python module called 'funcbundle' containing three specific functions. In the main program, these functions are used to calculate the average, minimum, and count of values below average from a list of integers provided by the user. All results are printed with relevant messages.

Step-by-step explanation:

Creating a Python Module with Functions

First, we need to define a module named funcbundle which will contain the required functions. Below are the function definitions:

# funcbundle.py

def get_average(data):
return sum(data) / len(data)

def get_min(data):
return min(data)

def get_below_avg_count(data):
average = get_average(data)
return sum(1 for x in data if x < average)

Next, in the main Python file, we can create a main function that prompts the user to input 10 integer values, then call these functions and print out the results.

# main.py
from funcbundle import get_average, get_min, get_below_avg_count

def main():
data = []
for i in range(10):
val = int(input("Enter an integer value: "))
data.append(val)

average = get_average(data)
minimum = get_min(data)
count_below_avg = get_below_avg_count(data)

print(f"The average value is: {average}")
print(f"The smallest value is: {minimum}")
print(f"The count of values below average is: {count_below_avg}")

if __name__ == "__main__":
main()
This code allows the user to input their data, after which the functions from funcbundle are used to calculate and display the average value, the smallest value, and the count of values below the average.
User Peter Stonham
by
8.6k points