Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use python Dic e Game: Pig (100 points) For this program you will build a simple dice game called Pig. In this version of
Please use python
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 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: 16Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started