Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am a beginner comp sci, so may not be familiar with all concepts, so I'd like simple ones. Program #3 Filename: pig . py

I am a beginner comp sci, so may not be familiar with all concepts, so I'd like simple ones.

image text in transcribedimage text in transcribed
Program #3 Filename: pig . py For this assignment, you'll implement a dice game called m, pitting two human players against each other. PIG is played with a standard six-sided die and proceeds as follows: Each player starts with zero points, and the rst to 20 points wins. The current player chooses to roll or hold. If they choose roll: 0 The six-sided die is rolled 0 The value of the die is added to their round points. 0 The player goes again UNLESS... o ...If the value on the die is 1, then the round is over and the player has lost all the points they accumulated in the round. If they choose hold: 0 The points accumulated in the round are added to the player's overall score. 0 The round is over. When the round ends (either because the player rolled a l or they chose to hold), it becomes the other player's turn unless somebody has won. We check to see if someone won at the end of each round (which is kind of unfair, because if Player One gets 20 points on the rst round, then Player Two never gets a chance, but oh well tough for them). Requirements: Prompt each player to either R (roll) or H (hold). If they enter anything else, continue prompting them until they enter a correct input. On a roll, randomly generate a value 1-6 to represent the die. End the round when the die roll is value 1 (round points are lost), or the player chooses Hold (round points are added to that player's overall score). End the game one either player has 20 or more points and announce the winner. Report everything as you go along -- what the die roll was, number of points so far, etc. As always with your CSSOOl programs, your inputr'output must be iendly and informative. Helpful hints Python has a random module that can help you generate random numbers. You probably want to import random for this part of the assignment and call randint (-.) import random # near the top of your file random.randint(1, 6) # or something like this in your program AMAZIN G points: Allow them to enter upper or lowercase letters. Rfr for roll, and HI]: for hold. Make your code extensible enough that we could add an arbitrary number of players with minimal coding-pain. (Consider using a list to store the player names and another list for the number of points each player has.) A sample run of your program might look something like this (except we set the winning threshold to 10 points for the example, instead of 20, so it wouldn't go on too long). actice/pig.py It is your turn, HUMAN TWO It is your turn, HUMAN ONE R - Roll R - Roll H - Hold H - Hold Enter your choice Enter your choice r r You rolled a 1 You rolled a 6 Wah wah waahh. . . round is over! Points in this round: 6 R - Roll H - Hold You got 0 that round! Enter your choice It is your turn, HUMAN ONE R - Roll r You rolled a 2 H - Hold Points in this round: 8 R - Roll Enter your choice H - Hold r You rolled a 5 Enter your choice Points in this round: 5 R - Roll You rolled a 2 H - Hold Points in this round: 10 R - Roll Enter your choice H - Hold h You got 5 that round! Enter your choice h It's over HUMAN ONE WINS! ! ! ! ! You got 10 that round

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What do you think Scoot should do next?

Answered: 1 week ago

Question

\f

Answered: 1 week ago