Related questions
Concept explainers
Phyton:
Program 6:
Write a program that allows the user to add data from files or by hand. The user may add more data whenever they want. The print also allows the user to display the data and to print the statistics. The data is store in a list. It’s easier if you make the list global so that other functions can access it.
You should have the following functions:
- · add_from_file() – prompts the user for a file and add the data from it.
- · add_by_hand() – prompts the user to enter data until user type a negative number.
- · print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions.
Handling errors such as whether the input file exist is extra credit.
To print a 10-column table, you can use the code below:
for i in range(len(data)):
print(f"{data[i]:3}", end="")
if (i+1)%10==0:
print()
print()
Sample run:
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 2
Type a positive number (-1 to end):1
Type a positive number (-1 to end):2
Type a positive number (-1 to end):3
Type a positive number (-1 to end):-1
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 4
1 2 3
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 1
Enter file to read: a.txt
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 4
1 2 3 3 1 4 5
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 1
Enter file to read: b.txt
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 4
1 2 3 3 1 4 5 9 8 5
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 2
Type a positive number (-1 to end):10 20
Type a positive number (-1 to end):20
Type a positive number (-1 to end):30
Type a positive number (-1 to end):-1
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 4
1 2 3 3 1 4 5 9 8 5
10 20 30
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 4
1 2 3 3 1 4 5 9 8 5
10 20 30
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 3
min = 1
max = 30
mean= 7.769230769230769
sum = 101
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4) view data
5) exit
Choice: 5
Goodbye
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 5 images
- This is question 5 on the same chapter 9arrow_forwardLottery number generator: Write a program that generates aseven-digit lottery number. The program should have a loopto generate seven random numbers, each in the range 0through 9 and assign each number to a list element.2. Write another loop to display the contents of the list.3. Tip: You will need to create/initialize your list before you canassign numbers to it.4. Use program 7-1 sales_list as an example. You will start witha seven-digit lottery number that contains all zeros. Then inyour loop, you will assign a random number instead ofgetting the data from the user.Turn in your program to the practice assignment link in coursecontent.arrow_forwardpython exercise: Write a Python function called get_top_students that takes the list of dictionaries as input and returns a dictionary containing the name and GPA of the top two students in the list. Each dictionary has the following keys: "name", "age", "major", and "gpa".arrow_forward
- Help me on below python program.arrow_forwardCommand Program Create a program that allows you to view and edit the sales amounts for each month of the current year. This program is required to use commands add, view, totals, edit, and exit. The program should use a list to store the sales data for each month with the three-letter abbreviation for the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec) to use as the key for each item. When the program starts, it should read the sales data inserted from the user. If the user edits the sales data, the program should edit the data If the user selects total, then the program should calculate the total sales and average monthly sales. Use functions to view sales, edit sales, calculate total, and calculate average. Please use all commands, and thank you in advance.arrow_forward5 partition_list (head) This is a little like split_list() from the Short problem, except that, instead of splitting the list into two by cutting it into the middle, you will now build two lists to return, using alternate values. The first value in the input list should be returned at the head of the first new list; the second value should be the head of the second list. Keep on alternating from there, putting one new value on the first list, and one on the second. (But remember that the length of the input list might be odd.) Example Suppose you have the following input list: 10 - 13 -> -1 -> 1000 - 0 It should return the following two lists: 10 1 0 13 -> 1000arrow_forward
- C Programming Language Task: Deviation Write a program that prompts the user to enter N numbers and calculates which of the numbers has the largest deviation from the average of all numbers. You program should first prompt the user to enter how many numbers that will specify. The program should then scan for each number, separated by a newline. You should calculate the average value and return the number from the list which is furthest away from this average (to 2dp). Try using dynamic memory functions to store the incoming array of numbers on the heap. Code to build from: + 1 #include 2 #include 3 4 int main(void) { 5 6} 7 Output Example: deviation.c How many numbers? 5 Enter them: 1.0 2.0 6.0 3.0 4.0 Average: 3.20 Largest deviation from average: 6.00arrow_forwardIn c++, Using STL containers, components, and algorithms show all data from the text file movies.txt. Please make sure the list updates once the user adds a new movie to the text file. Console Movies program COMMAND MENU show - user is able to see all available movies from movies.txt command: show The Adventures of a Babysitter 10ドル Barney 25ドル Larry the Car Man 15ドル Dora and the missing map 15ドル Ceasar and the Lunch Lady 10ドル Suzie and the Bad Kids 13ドル.95 command: add cout << "What movie do you want to add?"; cin >> BeeHive 12ドル; cout << "Movie added"; command:show The Adventures of a Babysitter 10ドル Barney 25ドル Larry the Car Man 15ドル Dora and the missing map 15ドル Ceasar and the Lunch Lady 10ドル Suzie and the Bad Kids 13ドル.95 Beehive 12ドル movies.txt with all possible movies: The Adventures of a Babysitter 10ドル Barney 25ドル Larry the Car Man 15ドル Dora and the missing map 15ドル Ceasar and the Lunch Lady 10ドル Suzie and the Bad Kids 13ドル.95arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education