Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dic e Game: Pig (100 points) For this program you will build a simple dice game called Pig. In this version of Pig, two players

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Dic e Game: Pig (100 points) For this program you will build a simple dice game called Pig. In this version of Pig, two players alternate turns. Players each begin the game with a score of 0. During a turn a player will roll a six-sided die one or more times, summing up the resulting rolls. At the end of the player's turn the sum for that turn is added to the player's total game score If at any time a player rolls a 1, the player's turn immediately ends and he/she earns O points for that turn (i.e. nothing is added to the player's total game score). This is called "pig". After every roll that isn't a 1, the player may choose to either end the turn, adding the sum from the current turn to his/her total game score, or roll again in an attempt to increase the sum. The first player to 50 points wins the game Details Open a text editor and create a new file called pig.py. In the file 1. Write a function called print_scores that has four parameters - these hold, in this order, the name of the first player (a string), his/her score (an int), the second player's name (a string), and score (an int). The function will a) Print the following message, using the current parameter values for the player names and scores (NOT necessarily Ziggy, 18, Elmer, and 23) -SCORES Ziggy:18 Elmer 23-- Print an empty line before this line There is a single tab between SCORES and the name of player 1 . There is a single tab between player 1's score and player 2's name . Every other gap is a single space 2. Write a function called check for winner that has two parameters: a name (a string) and a score (an int): a) If the score is 50 or more print the following message (using the current parameter value for the name, not Ziggy) b) The function returns True if the score is 50 or more, otherwise it returns False 2 3. Write a function called roll again that has a single string parameter to hold a player's name. In the function a) Entera while loop which repeats the following steps: Ask whether the player would like to roll again, using the following message: Roll again, Ziggy? (Y/N) There is a single space after (Y/N) . If the player answers with Y, y, N, or n, exit from the loop. Otherwise print the following message (replacing XXX with the user's entry) I don't understand: "XXX" Please enter either "Y" or "N" . b) The function returns either True or False depending on whether the player wants to roll again. 4. Write a function called play_turn that has a single string parameter, which holds a player's name. The function will a) Print the player's name as shown in the following example - Ziggy'sturn There are 10 hyphens on either side of the message Initialize a variable to keep track of the points the player earns on this turn The function then enters a while loop in which the player attempts to earn points. It repeats the following steps . Generate a random integer between 1 and 6 inclusive using the random module . Print a message displaying the roll as shown in the following example b) c) > Put a tab to the left of the first angle bracket If the roll is a 1: Print the following message !!! PIG! No points earned, sorry Ziggy * Put a tab to the left of the first exclamation point. Make sure the player earns no points for the turn. Make a change to ensure you exit the loop or exit directy Use the following message to pause the program until the user is ready to continue (enter to continue) If the roll is not a 1 Add the roll to the player's points earned for the turn. Print the player's turn total as in the following example Points: 12 * Put a tab to the left of the word Points Use the roll_again function to ask the player if he/she would like to roll again If not, make a change to ensure you exit the loop or exit directly d) Make sure that you returned the number of points earned by the player for this turn in all cases 5. In main: a) Get an integer to use for the random.seed function from the user with the prompt Enter seed value: Pass random. seed the value retrieved from the user, (MAKE IT AN int) Print two blank lines followed by the title of the game Pig Dice Ask the user to enter the first player's name with this prompt: Enter name for player 1: Ask the user to enter the second player's name with this prompt Enter name for player 2: Print a greeting message in the following form: Hello Ziggy and Elmer, welcome to Pig Dice! b) c) d) e) f) Put a tab to the left of Hello. g) Initialize the players' scores to 0 h) Print their scores using the print_scores function. i) Enter a while loop in which repeats the following steps Call the play turn function for player 1 and add any earned points to his/her total score. Print the players' scores (use the appropriate function) Check whether player 1 won the game (use the appropriate function) If player 1 didn't win, call the play_turn function for player 2 and add any earned points to his/her total Print the players' scores. Check whether player 2 won the game. If either player won the game, ensure that you exit the while loop . 6. Verify that your documentation makes sense and that you've added documentation to each of your functions Verify that your program works properly Upload your file to the Hw4 Assignments folder on D2L. 7. 8. Below is an example of the output from running the finished program. If you enter 125 for the seed and make the same choices as the players do in this example your output should look like this. Printed output is in blue, user input is in green Enter seed value 125 Pig Dice Enter name for player1: Ziggy Enter name for player 2: Elmer Hello Ziggy and Elmer, welcome to Pig Dice! ziggy: o Elmer: 0 -- ----Ziggy's turn-- >> Points: 2 Roll again, Ziggy? (Y/N) Y >> Points: 4 Roll again, Ziggy? (Y/N) Y >> Points: 9 Roll again, Ziggy? (Y/N) N SCORES Ziggy : 9 Elmer: 0 Elmer's turn--- >> Points: 3 Roll again, Elmer? (Y/N) Y >> Points 8 Roll again, Elme? (Y/N) Y > Points: 14 Roll again, Elmer? (Y/N) Y >> Points: 16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions