Reference no: EM132356467
Question
Suppose we have a text file, records.txt, of people's names and their weights. Each line of the file contains one name and one weight, separated by a single space.
Here is a sample file: Jack 80 Jill 100 Peter 96 Jenny 155 Write the definition of the function avg_weight, which returns the average weight of the people included in the file.
The function takes in a one character config parameter, calculating the average weights of people whose names begin with the letter specified in the config parameter.
If given the letter J, with the function call avg_weight(‘J'), the function would only compute the average weight people whose names began with the letter J - Jack, Jill, and Jenny, ignoring Peter's weight, in the sample file shown above. If given the star character * however, with the function all avg_weight(‘*') , the function includes the weight of every person in the file in the calculation.
def avg_weight(config: str) -> float