Hide

Problem E
Analyze List

Write a program that given a list $\ell $ of positive integers, prints out the following information:

  1. The list $\ell $.

  2. The sorted version of $\ell $.

  3. A sorted list of the composite numbers in $\ell $ (composite numbers are numbers that are not prime). The resulting list should only include each value once.

  4. Minimum, maximum, and average values in $\ell $. 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 $\ell $.

If the list $\ell $ contains invalid values then the program should ask for another list until a valid list is given.

In the tests, each $\ell $ will be a list of length $1$ to $1\, 000$. The elements of the list will be integers or letters of the English alphabet.

Output

The output should contain at least $4$ lines. First if the user input an invalid list the program should display.
Incorrect input! Please try again.” for every invalid input until a valid one is encountered.
Then the program should print the following four lines:

  1. Input list: {$\ell $}”.

  2. Sorted list: {$s$}” where $s$ is the list $\ell $ sorted.

  3. Composite list: {$c$}”, where $c$ is a list of composite numbers in $\ell $.

  4. Min: {$\ell _{min}$}, Max: {$\ell _{max}$}, Average: {$\mu $}

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

Please log in to submit a solution to this problem

Log in