Objective
Create a Python program that generates mathematical statistics. The program stores up to 1000 decimal numbers in a list and shows a menu with several options. It runs until the user selects the exit option.
The menu has the following options (1-5): Add, View, Search, Statistics and Exit.
Functionalities
- Add: the user adds a new value to the list. Make sure not to exceed 1000 values.
- View: shows the list of values in a single line. There may be no values yet.
- Search: asks the user for a real number and determines whether it exists in the list. There may be no values yet.
- Statistics: shows a summary of the values in the list: the total number of values, the sum, the arithmetic mean and the maximum and minimum values.
- Exit: ends the program.
Input and output format. Do not print prompts: read every option and value with input(), one per line. Before reading each option print the menu (1. Add, 2. Show, 3. Search, 4. Statistics, 5. Exit) followed by an empty line. Add reads a value (if there are already 1000 values, it prints The database is full). Show prints the values separated by a space, or Data not available if there are none. Search reads a value and prints Number X found or Number not found (Data not available if the list is empty). Statistics prints Total data: N, Sum: X, Average: X, Min value: X and Max value: X (or Data not available). Any other option prints Valid options (1-5). Print every number with up to 6 significant digits and no trailing zeros (7, 2.5, 1.66667); in Python, the :g format.
1
7
2
3
6
4
5
1. Add
2. Show
3. Search
4. Statistics
5. Exit
1. Add
2. Show
3. Search
4. Statistics
5. Exit
7
1. Add
2. Show
3. Search
4. Statistics
5. Exit
Number not found
1. Add
2. Show
3. Search
4. Statistics
5. Exit
Total data: 1
Sum: 7
Average: 7
Min value: 7
Max value: 7
1. Add
2. Show
3. Search
4. Statistics
5. Exit
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise