Problem 25
Develop an algorithm for finding the most frequently occurring value in a list of numbers. Use a sequence of coins. Place paper clips below each coin that count how many other coins of the same value are in the sequence. Give the pseudocode for an algorithm that yields the correct answer, and describe how using the coins and paper clips helped you find the algorithm.
Problem 26
How do you perform the following tasks with lists in Python? a. Test that two lists contain the same elements in the same order. b. Copy one list to another. c. Fill a list with zeroes, overwriting all elements in it. d. Remove all clements from a list.
Problem 26
A theater seating chart is implemented as a table of ticket prices, like this: $$ \begin{array}{llllllllll} 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 \\ 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 \\ 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 & 10 \\ 10 & 10 & 20 & 20 & 20 & 20 & 20 & 20 & 10 & 10 \\ 10 & 10 & 20 & 20 & 20 & 20 & 20 & 20 & 10 & 10 \\ 10 & 10 & 20 & 20 & 20 & 20 & 20 & 20 & 10 & 10 \\ 20 & 20 & 30 & 30 & 40 & 40 & 30 & 30 & 20 & 20 \\ 20 & 30 & 30 & 40 & 50 & 50 & 40 & 30 & 30 & 20 \\ 30 & 40 & 50 & 50 & 50 & 50 & 50 & 50 & 40 & 30 \end{array} $$ Write a program that prompts users to pick cither a seat or a price, Mark sold seats by changing the price to 0 . When a user specifies a seat, make sure it is available. When a user specifies a price, find any scat with that price.
Problem 27
True or false? a. List index values must be integers. b. Lists can change their size, getting larger or smaller. c. A function cannot return a list. d. All elements of a list are of the same type. e. Lists cannot contain strings as clements. f. A function cannot change the length of a list argument.
Problem 27
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a \(3 \times 3\) grid as in the photo at right. The game is played by two players, who take turns. The first player marks moves with a circle, the second with a cross. The player who has formed a horizontal, vertical, or diagonal sequence of three marks wins. Your program should draw the game board, ask the user for the coordinates of the next mark, change the players after every successful move, and pronounce the winner.
Problem 28
Write a function def appendlist \((a, b)\) that appends one list after another. For example, if a is \(\begin{array}{lll}1 & 49 & 16\end{array}\) and \(\mathrm{b}\) is \(\begin{array}{lllll}9 & 7 & 4 & 9 & 11\end{array}\) then append returns a new list containing the values \(\begin{array}{lllllllll}1 & 4 & 9 & 16 & 9 & 7 & 4 & 9 & 11\end{array}\)
Problem 28
Write Python statements for performing the following tasks with a table of a rows and n columns. \- Initialize the table with zeroes. \- Fill all entries with ones. \- Fill elements alternately with zeroes and ones in a checkerboard pattern. \- Fill only the elements in the top and bottom row with zeroes. \- Fill only the elements in the left and right column with ones. \- Compute the sum of all elements. \- Print the table.
Problem 30
Write a function def mergesorted \((a, b)\) that merges two sorted lists, producing a new sorted list. Keep an index into each list, indicating how much of it has been processed already. Each time, append the smallest unprocessed element from either list, then advance the index. For example, if a is 14916 and \(b\) is \(\begin{array}{lllll}4 & 7 & 9 & 9 & 11\end{array}\) then mergesorted returns a new list containing the values \(\begin{array}{lllllllll}1 & 4 & 4 & 7 & 9 & 9 & 9 & 11 & 16\end{array}\)
Problem 35
You are given a table of values that give the height of a terrain at different points in a square. Write a function def floodMap (heights, waterLevel) that prints out a flood map, showing which of the points in the terrain would be flooded if the water level was the given value. In the flood map, print a = for each flooded point and a space for each point that is not flooded.
Problem 36
Sample values from an experiment often need to be smoothed out. One simple approach is to replace each value in a list with the average of the value and its two neighboring values (or one neighboring value if it is at either end of the list). Implement a function that carries out this operation. You should not create another list in your solution.