Problem E
Analyze List
Write a program that given a list
-
The list
. -
The sorted version of
. -
A sorted list of the composite numbers in
(composite numbers are numbers that are not prime). The resulting list should only include each value once. -
Minimum, maximum, and average values in
. The average value should be formatted to two decimal places.
The function is_prime() is given.
You need to print out an error message if the user enters invalid values into the list, and ask the user again for input until valid input is given.
Input
The input consists of one or more lines, each containing a
list
If the list
In the tests, each
Output
The output should contain at least
“Incorrect input! Please try again.”
for every invalid input until a valid one is encountered.
Then the program should print the following four lines:
-
“Input list: {
}”. -
“Sorted list: {
}” where is the list sorted. -
“Composite list: {
}”, where is a list of composite numbers in . -
“Min: {
}, Max: { }, Average: { }”
Sample Input 1 | Sample Output 1 |
---|---|
2,5,7,2,8,10,34,23,9,4,5 |
Input list: [2, 5, 7, 2, 8, 10, 34, 23, 9, 4, 5] Sorted list: [2, 2, 4, 5, 5, 7, 8, 9, 10, 23, 34] Composite list: [4, 8, 9, 10, 34] Min: 2, Max: 34, Average: 9.91 |
Sample Input 2 | Sample Output 2 |
---|---|
4,7,2,9,11,13,22,5,33,7,13 |
Input list: [4, 7, 2, 9, 11, 13, 22, 5, 33, 7, 13] Sorted list: [2, 4, 5, 7, 7, 9, 11, 13, 13, 22, 33] Composite list: [4, 9, 22, 33] Min: 2, Max: 33, Average: 11.45 |
Sample Input 3 | Sample Output 3 |
---|---|
5,7,x 3, -4, 5, -6 2,8,8 |
Incorrect input! Please try again. Incorrect input! Please try again. Input list: [2, 8, 8] Sorted list: [2, 8, 8] Composite list: [8] Min: 2, Max: 8, Average: 6.00 |