#K44647. Average Sales Calculation
Average Sales Calculation
Average Sales Calculation
You are given a JSON object representing the daily sales figures for several items. Each key in the JSON object is an item name and the corresponding value is a list of integers representing daily sales. Your task is to calculate the average sales for each item and output the results as a JSON object.
The average is computed as follows:
\( \text{average} = \frac{\text{sum of daily sales}}{\text{number of days}} \)
You should read the input from stdin and write the result to stdout. Make sure to output the JSON object exactly as specified.
inputFormat
The input consists of a single JSON object provided via stdin. The JSON object has keys representing item names (strings) and values that are lists of integers (daily sales figures). You can assume that each list contains at least one integer.
Example:
{ "apple": [10, 12, 20, 15, 18, 16, 25], "banana": [5, 7, 8, 6, 10, 12, 9], "cherry": [2, 3, 4, 1, 2, 3, 5] }
outputFormat
Your program should output a single JSON object to stdout. This JSON object should contain the same keys as the input and their corresponding values should be the computed average (as a floating-point number) of the provided list of integers.
Example:
{ "apple": 16.571428571428573, "banana": 8.142857142857142, "cherry": 2.857142857142857 }## sample
{
"apple": [10, 12, 20, 15, 18, 16, 25],
"banana": [5, 7, 8, 6, 10, 12, 9],
"cherry": [2, 3, 4, 1, 2, 3, 5]
}
{"apple": 16.571428571428573, "banana": 8.142857142857142, "cherry": 2.857142857142857}