Please read the instructions below carefully and follow them closely. All problems (and parts of problems) are required except as noted below. Note: For any functions you are asked to write, you must use the exact function names given in the descriptions, and you must have parameters in the order shown in the description. Note: to people who know what default values and/or keyword arguments are: do not use default values and do not use keyword arguments. If you don’t know what these are it is unlikely you’ll do it by accident. Ask us if you’re not sure. Before you begin working on your program you’ll need to learn a bit about the random module. In a Python shell:∗ run that same statement many times until you know what it does – enter: random.randint(0,3)∗ run that same statement many times until you know what it does – enter: random.randint(4,6)∗ run that same statement many times until you know what it does – enter: random.randint(1,100)∗ What does it do? For this program you will build a simple dice game called “Pig”.In this version of Pig, two players will 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 0 points for that turn (i.e. nothing is added to the player’s total game score). After every roll 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.Open a text editor and create a new file called “pig.py”. In the file:i.) Print the following message, using the current parameter values for the player names and scores (i.e. the value in name1 instead of Ziggy, the value in score1 instead of 18, etc): — SCORES Ziggy: 18 Elmer: 23 —– Write code in main to test your function and verify it works correctly before moving on i.) if the score is 50 or more print the following message (obviously using the current parameter value for the name): THE WINNER IS: Ziggy!!!!!– Write code in main to test your function and verify it works correctly before moving on (you may wish to comment out the code you used to test the previous function) i.) Enter a while loop in which it repeats the following steps:a.) Ask whether the player would like to roll again, using the following message:Roll again, Ziggy? (Y/N)I don’t understand: “XXX”. Please enter either “Y” or “N”.– Write code in main to test your function and verify it works correctly before moving on (you may wish to comment out the code you used to test the previous function) i.) Print the player’s name as shown in the following example (again, obviously using the current parameter value for the name): ———- Ziggy’s turn ———-<<< Ziggy rolls a 4 >>>c.) if the roll is a 1:!!! PIG! No points earned, sorry Ziggy !!!d.) if the roll is not a 1:Points: 12 e.) finally return the number of points earned by the player for this turn– Write code in main to test your function and verify it works correctly before moving on (you may wish to comment out the code you used to test the previous function) Enter seed value:Hello Ziggy and Elmer, welcome to Pig Dice!x.) Enter a while loop in which you repeat the following steps: e.) if either player won the game ensure that you exit the while loop 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 exactly like this (note that spacing might not reproduce perfectly in this PDF, see instructions above for exact spacing used). User entered values are highlighted. Enter seed value: 125 Pig DiceEnter name for player 1:Enter name for player 2: rHello Ziggy and Elmer, welcome to Pig Dice! — SCORES Ziggy: 0 Elmer: 0 ————- Ziggy’s turn ———-<<< Ziggy rolls a 2 >>>Points: 2Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 2 >>>Points: 4Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 5 >>>Points: 9Roll again, Ziggy? (Y/N) N — SCORES Ziggy: 9 Elmer: 0 ————- Elmer’s turn ———-<<< Elmer rolls a 3 >>>Points: 3Roll again, Elmer? (Y/N) Y<<< Elmer rolls a 5 >>>Points: 8Roll again, Elmer? (Y/N) Y<<< Elmer rolls a 6 >>>Points: 14Roll again, Elmer? (Y/N) Y<<< Elmer rolls a 2 >>>Points: 16Roll again, Elmer? (Y/N) N — SCORES Ziggy: 9 Elmer: 16 ————- Ziggy’s turn ———- <<< Ziggy rolls a 3 >>>Points: 3Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 2 >>>Points: 5Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 5 >>>Points: 10Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 3 >>>Points: 13Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 5 >>>Points: 18Roll again, Ziggy? (Y/N) N — SCORES Ziggy: 27 Elmer: 16 ————- Elmer’s turn ———-<<< Elmer rolls a 6 >>>Points: 6Roll again, Elmer? (Y/N) Y<<< Elmer rolls a 1 >>>!!! PIG! No points earned, sorry Elmer !!!(enter to continue) — SCORES Ziggy: 27 Elmer: 16 ————- Ziggy’s turn ———-<<< Ziggy rolls a 1 >>>!!! PIG! No points earned, sorry Ziggy !!!(enter to continue) — SCORES Ziggy: 27 Elmer: 16 ————- Elmer’s turn ———- <<< Elmer rolls a 6 >>>Points: 6Roll again, Elmer? (Y/N) N — SCORES Ziggy: 27 Elmer: 22 ————- Ziggy’s turn ———- <<< Ziggy rolls a 6 >>>Points: 6Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 2 >>>Points: 8Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 4 >>>Points: 12Roll again, Ziggy? (Y/N) Y<<< Ziggy rolls a 5 >>>Points: 17 and so on…
130:, 5, and, Assignment, If, ISTA, Loops, Programming, solved, statements, While
[SOLVED] Ista 130: programming assignment 5 while loops and if statements
$25
File Name: Ista_130:_programming_assignment_5_while_loops_and_if_statements.zip
File Size: 602.88 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.