This is one full question. Please write in Python.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

This is one full question. Please write in Python.

Post by answerhappygod »

This is one full question. Please write in Python.
This Is One Full Question Please Write In Python 1
This Is One Full Question Please Write In Python 1 (518.31 KiB) Viewed 31 times
This Is One Full Question Please Write In Python 2
This Is One Full Question Please Write In Python 2 (280.64 KiB) Viewed 31 times
This Is One Full Question Please Write In Python 3
This Is One Full Question Please Write In Python 3 (354.88 KiB) Viewed 31 times
4. 2D lists are very useful for organizing large amounts of data. For example, suppose we have the following data on the number of points scored by each player on a basketball team over each game of a seven-game series. (If computer scientists ruled the world, the NBA Finals would totally start from Game 0. Someday...) Player Tim the Enchanter Dora the Explorer Catherine the Great Suleiman the Magnificent Top the Inept Game 0 Game 1 20 27 8 18 34 19 17 8 2 0 Game 2 Game 3 16 23 11 17 25 22 11 34 0 sun3 Game 4 20 9 19 15 10 Game 5 Game 6 27 18 12 0 25 31 0 9 2 0 This information can be stored in a 2D list, where each row of the list represents a player and each column represents a game. Index [j] of this list is the number of points scored by player i in game j (where both i and j start counting from 0). For example, index [0] [5] is Tim the Enchanter's points scored in Game 5. In this problem, we'll investigate finding the mode (element that appears most frequently) of data in this format. Within a file named omg sports.py, do the following: (a) (8 points) Write a function find mode (x) that finds and returns the mode(s) of the 1D list x. The mode(s) should be returned in a 1D list, even if there's only one mode. If there are multiple modes, the function should return all of them, in the order that they were encountered in x. Note: No credit will be given for using any built-in Python implementation of mode finding. The point of this problem is to think about how you can find the mode yourself! Hint: Start by counting how many times each list element appears. A dictionary can be very useful to store this information... Here are some example arguments and their expected return values: Argument [1, 2, 3, 3] [1, 1, 2, 3, 3] Return Value [3] [1, 3]
Argument [1, 2, 3, 3] (1, 1, 2, 3, 3] [1, 2, 3, 2, 1, 3] Return Value [3] (1, 3] [1, 2, 3] > > > > > (b) (1 point) Write a function find_player mode (scores, p). The parameter scores is a 2D list of scores formatted as described earlier, and the parameter p is the index of a player. The function returns a 1D list of the most common per-game scores for player p. Call the previously written find mode function as needed this should be doable in one line! Here are some example arguments and their expected return values. In the examples below, assume scores is a 2D list containing the data from the beginning of this problem. a
Return Value Arguments (scores, 0) [20, 27] Notes Tim scored 20 twice and 27 twice Suleiman scored a different number of points in all seven games Top scored 0 points three times (scores, 3) [17, 8, 11, 34, 15, 0, 9] (scores, 4) [O] (c) (2 points) Write a function find game mode (scores, g). The parameter scores is a 2D list of scores formatted as described earlier, and the parameter g is the index of a game. The function returns a 1D list of the most common per-player scores for game g. Call the previously written find mode function as needed. Here are some example arguments and their expected return values. In the examples below, assume scores is a 2D list containing the data from the beginning of this problem. Arguments Return value (scores, 0) (20, 8, 34, 17, 2] (scores, 2) [11] Notes In Game 0, all five players scored different numbers of points In Game 2, two players scored 11 points (d) (3 points) Below your function definitions in omg-sports.py, write the necessary code to create the 2D list of scores from earlier. Call your find player mode and find game mode functions using at least the test cases presented here. You're welcome to add more tests too, to convince yourself that the functions work!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply