Test Scores program
Exercise 6-1
Use a list for the Test Scores program In this exercise, you’ll modify a Test Scores program that gets the test scores that a user enters and then calculates and displays the average test score. You’ll enhance this program by storing the test scores in a list and then getting and displaying other statistics for the test scores, like this: The Test Scores program Enter ‘x’ to exit Enter test score: 75 Enter test score: 85 Enter test score: 95 Enter test score: x Total: Low Score: High Score: Median Score 255 Number of Scores: 3 Average Score: 85 75 95 85 1. In IDLE, open the test_scores.py file that’s in this folder: python/exercises/ch06 2. Review the code, and test the program. 3. Modify the get_scores() function so the test scores are stored in a list named scores. This list should be returned by the function when all scores have been entered. The function should still make sure that the entries are valid, but the score_total and count variables aren’t needed and shouldn’t be updated. 4. Modify the process_scores() function so the scores list is its only argument. Then, this function should use a for statement to total the scores in the list. It should use the len() function to get the number of scores in the list. And it should get the average by dividing the total scores by the length. 5. Modify the main() function so the list that’s returned by the get_scores() function is stored in a variable. Then, modify the call to the process_scores() function so it passes just the scores list to it. 6. Test this program to make sure everything is working right. 7. Enhance this program by getting and displaying all of the other statistics shown above. For an odd number of scores, the median score is the score that has the same number of scores below it as above it. For an even number of scores, calculate the median by taking the average of the two middle numbers.
Exercise 6-2
Enhance the Movie List 2D program In this exercise, you’ll modify the Movie List 2D program in figure 6-7 so it provides a third column for each movie. Otherwise, this program should work the same way it did before: COMMAND MENU list – List all movies add – Add a movie del – Delete a movie find – Find movies by year exit – Exit program Command: add Name: Gone with the Wind Year: 1939 Price: 14.95 Gone with the Wind was added. Command: list 1. Monty Python and the Holy Grail (1975) @ 9.95 2. On the Waterfront (1954) @ 5.59 3. Cat on a Hot Tin Roof (1958) @ 7.95 4. Gone with the Wind (1939) @ 14.95 Command: find Year: 1954 On the Waterfront was released in 1954 Command: 1. In IDLE, open the movie_list_2d.py file that’s in this folder: python/exercises/ch06 2. Enhance the program so it provides for the price column that’s shown above. 3. Enhance the program so it provides a find by year function that lists all of the movies that were released in the year that the user requests, as shown above.