Write a function summarizeList(numberString). numberString is a string of numbers separated by commas, like so:
"6,0,1.5"
This function should find the min, median, and max of the numbers, as well as the average. This function should return a string like the following:
"The numbers range from 0 to 6; The median is 1.5. The average is 2.5
Note: feel free to use builtin functions like sum() or string.format() in writing this.
# ==== Test cases:
summarizeList("6,0,1.5")
# should return: "Numbers range from 0.0 to 6.0; The median is 1.5; The average is 2.5"
summarizeList("5,-10,3,2")
# should return: "Numbers range from -10.0 to 5.0; The median is 2.5; The average is 0.0;"
summarizeList("7,15,3,2.8,10,11,2.6,9")
# should return: "Numbers range from 2.6 to 15.0; The median is 8.0; The average is 7.55;"
I recommend you approach the problem
in steps, testing/printing at each step
to make sure it works correctly.
- Just turn the string into a list of numbers and sort it
- Find the min, max, average (without the median)
- Create and return the correctly formatted output string
- Find the median, and make sure it's calculated correctly for all test cases