Here's the code for the squares function as a generator function:
python
import statistics
def squares(*args):
avg = statistics.mean(args)
for arg in args:
yield (arg - avg)**2
In the main program, we can call the squares function with the input parameters and iterate over the results using a for loop:
scss
values = (3, 4, 5)
for square in squares(*values):
print(square)
This will output:
1
0
1
Alternatively, we can call the squares function with a list of values:
scss
values = [2, 7, 3, 12]
for square in squares(*values):
print(square)
This will output:
16
1
9
36
In both cases, the squares function calculates the average of the input values using the statistics library and then yields the square of the difference between each value and the average using a generator function.