Question 4 (this question MAY BE GRADED) Write a Python program, in a file called number_guessing.py,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 4 (this question MAY BE GRADED) Write a Python program, in a file called number_guessing.py, to play a number guessing game with two players. The game is played for a fixed number of "sets" as pre-determined by the players. For each set, each player is given 2 tries to guess the value of a randomly generated number (between 1 and 6, inclusive). A different random number is used for each player, for each set. If the player guesses the number on the first try, they get 5 points (and don't have to guess again), if they guess the number on the second try, they get 3 points, otherwise they get no points. The player with the highest number of points, at the end of all sets, wins the game (or there can be a tie/draw). Your program should include the following functions: function main to do the following: . O obtain as input, the number of sets that the players wish to play O obtain the name of the two players for each set of the game, and for each player, randomly generate the number to be guessed compute and return the points for a player, at a given set, using the function computePoints (see description below) o print the results of each set (see sample output below) O print the winner of the game (after all sets are played) using the function printWinner (see description below) Note: Study the given sample input/output to see what and how the input should be obtained and how the output should be generated. O O function computePoints which, given the player name and the random number for a player, asks the player for their guesses, and computes and returns the number of points obtained (as described above) function printWinner which, given the total points and names of each player, prints the results (winner's name or "tie/draw" message). Question 4 (this question MAY BE GRADED) Write a Python program, in a file called number_guessing.py, to play a number guessing game with two players. The game is played for a fixed number of "sets" as pre-determined by the players. For each set, each player is given 2 tries to guess the value of a randomly generated number (between 1 and 6, inclusive). A different random number is used for each player, for each set. If the player guesses the number on the first try, they get 5 points (and don't have to guess again), if they guess the number on the second try, they get 3 points, otherwise they get no points. The player with the highest number of points, at the end of all sets, wins the game (or there can be a tie/draw). Your program should include the following functions: function main to do the following: . O obtain as input, the number of sets that the players wish to play O obtain the name of the two players for each set of the game, and for each player, randomly generate the number to be guessed compute and return the points for a player, at a given set, using the function computePoints (see description below) o print the results of each set (see sample output below) O print the winner of the game (after all sets are played) using the function printWinner (see description below) Note: Study the given sample input/output to see what and how the input should be obtained and how the output should be generated. O O function computePoints which, given the player name and the random number for a player, asks the player for their guesses, and computes and returns the number of points obtained (as described above) function printWinner which, given the total points and names of each player, prints the results (winner's name or "tie/draw" message).
Expert Answer:
Related Book For
Guide To Java A Concise Introduction To Programming
ISBN: 978-3031228414
2nd Edition
Authors: James T. Streib, Takako Soma
Posted Date:
Students also viewed these programming questions
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Assume C is a circle centered at the origin, oriented counterclockwise, that encloses disk R in the plane. Complete the following steps for the vector field F = (9y, - 2x). a. Calculate the...
-
Refer to Apple's financial statements in Appendix A to answer the following. 1. Identify the items, if any, that make up Apple's long-term debt as reported on its balance sheet at September 29, 2012....
-
What factors can be used to measure efficiency?
-
Analyze the methanol oxidation data in Table B. 20 for multicollinearity. x1 X2 X3 X4 xs 0 454 8.8 3.90 1.30 1.1 474 8.2 3.68 1.16 4.2 524 7.0 2.78 1.25 94.2 503 7.4 2.27 1.57 20.7 493 7.6 2.40 1.55...
-
Cabot Appliances, a retail chain, is trying to decide what size order it should place with its supplier of room air conditioners. Room air conditioner sales are highly seasonal, and the number of...
-
dy 1. Find and simplify. dx tanx (a) y= (3 marks) (b) y x cosh (In x) (3 marks) (c) + sinh 2y = y - cosh 2x (4 marks)
-
Explain what Ruskin means in Modern Painters when he says "that the art is greatest which conveys to the mind of the spectator, by any means whatsoever, the greatest number of the greatest ideas."
-
Develop the appropriate primary research question to be associated with this design, including the research questions that will address main effects and interactions. Develop a hypothetical research...
-
A metaphor places two dissimilar objects into a close relationship such that A is B, whereas a simile compares two objects such that A is like B. A and B, however dissimilar, share some quality that...
-
Describe why the longitudinal design is the most appropriate methodology to be used, considering the research scenario. Develop a hypothetical research scenario that would necessitate the use of a...
-
A brand that wants customers to see it as a friend by depicting a model using it is more effective when the product image appears horizontally and near the model. On the other hand, if a brand wants...
-
Discuss how the only form of control (statistical procedures) will be used in this scenario. Develop a hypothetical research scenario that would necessitate the use of a Longitudinal Design. The...
-
Compare the monthly payments and total loan costs for the following pairs of loan options. Assume that both loans are fixed-rate and have the same closing costs. You need a $140,000 loan. Option 1: a...
-
Ball bearings are widely used in industrial applications. You work for an industrial food machinery manufacturer and your role is to design the driveshaft assembly on a new type of equipment that...
-
Repeat the previous exercise using a case structure instead of a selection structure. Data From previous Exercise The dew point temperature is a good indicator of how humid it feels during a hot day....
-
Plot execution times of several runs of the complete program shown in Fig. 12.6 with a different number of threads and see the speed up.
-
Write code to output the following pattern: ** ** ** * * **** * ** **
-
Do any problems arise when translating physical assets and economic events into monetary units? Give one or two illustrations to support your answer.
-
Entries for the Warren Clinic 2015 income statement are listed below in alphabetical order. Reorder the data in proper format. Depreciation expense General/administrative expenses Interest expense $...
-
Bright Horizons Skilled Nursing Facility, an investor-owned company, constructed a new building to replace its outdated facility. The new building was completed on January 1, 2015, and Bright...
Study smarter with the SolutionInn App