Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
Dice game
Rules of the game:
The players roll three dice, and the program adds the sides that turn up.
After the first roll of the three dice, a player may choose to roll the dice as many times as they wish until the player gets at least one side 2 from a dice.
When a player gets at least one side 2 from the dice, that player's score drops to zero, and the turn switches to the other player.
Both players play the game for an equal number of turns, and the player who gets a score higher than 18 wins.
If both players get a score higher than 18 within an equal number of turns, the player with the higher score wins.
If both of the players got the same scores, print the scores of the players.
These are the minimum required functions for this program. Design and implement these functions. You can create more functions if you choose to.
Here is the provided starter code:
# A program to play a Dice game.
import random
def roll_die():
''' Simulate a die roll '''
def player_turn(player_name, other_player, player_score):
'''
Implements what happens on player's turn.
Returns player's score, which represents
the player's total score.
'''
option = 'r'
print(f'\n*******{player_name}\'s turn********\n')
# < Insert the rest of your code here. >
return player_score
def main():
'''
The main driver of the program. Call
the player_turn() functions here.
'''
# < Insert the rest of your code here. >
if __name__ == '__main__':
main()
Notes
Study the example output below to understand the behavior of the program. To keep the game from running too fast, when one player gets a side 2, that player must press the enter key to switch the turn to the other player.
Both players will play the game at least for one turn and an equal number of turns.
Example 1
When prompted, the user enters "p" or "r" to determine whether to pass or roll. When one of the players gets one or more side 2 from rolling the die, the player’s score drops to zero, and the player presses the enter key to switch players.
The players’ names go on the first and second lines. The first roll for Julie is a 6, 1, and 3 for a total score of 10. Julie rolls the die again. 1, 4, and 4 are rolled for a total score of 19. Since Julie scored higher than 18, the turn is switched to the second player. Jack got 4, 4, and 6 within the first roll for a total score of 14. He chooses to roll again and gets a score of 24. Since Jack’s total is greater than 18 and Julie’s total, the game is over, and Jack wins.
Enter the first player name: Julie
Enter the second player name: Jack
*******Julie's turn********
Scores: 6, 1, and 3.
Julie's score: 10
(p)ass or (r)oll? r
Scores: 1, 4, and 4.
Julie's score: 19
*******Jack's turn********
Scores: 4, 4, and 6.
Jack's score: 14
(p)ass or (r)oll? r
Scores: 1, 3, and 6.
Jack's score: 24
Jack wins with a score of 24
Example 2
Jill rolls the dice and passes the turn to Julie. Julie rolled a 2, so her score remains zero, and the turn is passed to Jill. Jill also got at least one 2, so her score drops to zero, and the turn is passed to Julie. Julie got a score of 15 and passes the turn to Jill. Jill got a 2 again, and her score remains zero. The turn passes to Julie. Julie scores 21, and wins the game. Note that the game starts with Jill’s turn and finishes with Julie’s turn. Therefore, they had equal turns.
Enter the first player name: Jill
Enter the second player name: Julie
*******Jill's turn********
Scores: 1, 3, and 4.
Jill's score: 8
(p)ass or (r)oll? p
*******Julie's turn********
Scores: 2, 5, and 1.
Julie got at least one 2.
Julie's score: 0
Press to continue ...
*******Jill's turn********
Scores: 2, 2, and 3.
Jill got at least one 2.
Jill's score: 0
Press to continue ...
*******Julie's turn********
Scores: 6, 3, and 6.
Julie's score: 15
(p)ass or (r)oll? p
*******Jill's turn********
Scores: 5, 5, and 2.
Jill got at least one 2.
Jill's score: 0
Press to continue ...
*******Julie's turn********
Scores: 4, 1, and 1.
Julie's score: 21
Julie wins with a score of 21
Example 6
In this example, Julie and Jack got the same score. So, the players’ scores are printed.
Enter the first player name: Julie
Enter the second player name: Jack
*******Julie's turn********
Scores: 6, 4, and 6.
Julie's score: 16
(p)ass or (r)oll? r
Scores: 1, 1, and 5.
Julie's score: 23
*******Jack's turn********
Scores: 5, 4, and 6.
Jack's score: 15
(p)ass or (r)oll? r
Scores: 4, 1, and 3.
Jack's score: 23
Both players got the same score
Julie: 23 scores
Jack: 23 scores
Transcribed Image Text:• If both players get a score higher than 18 within an equal number of turns, the player with the higher
score wins.
• If both of the players got the same scores, print the scores of the players.
These are the minimum required functions for this program. Design and implement these functions. You
can create more functions if you choose to.
Function name
Function description
roll_die()
player_turn()
main()
Starter file
Rolls a 6-sided die
Simulates a player's turn
Notes
Driver function that calls all the
functions above.
Function input(s)
None
Current player's
name, other player's
name, and current
player's score
None
Function
output(s)/
return value(s)
Side of the die
The current
player's
updated score
https://drive.google.com/file/d/1FUwMEpx0lv5FFG2Hf8iBWKF7CHOXYcoC/view?usp=sharing
<>
Transcribed Image Text:1:39
<
Julie wins with a score of 21
Example 3
Enter the first player name: Liam
Enter the second player name: Oliver
*******Liam's turn********
Scores: 5, 4, and 5.
Liam's score: 14.
(p)ass or (r)oll? r
Scores: 5, 6, and 6.
Liam's score: 31
*******Oliver's turn********
Scores: 2, 5, and 1.
Oliver got at least one 2.
Oliver's score: 0
Press <enter> to continue...
Liam wins with a score of 31
Example 4
Enter the first player name: Noah
Enter the second player name: James
*******Noah's turn********
Scores: 3, 2, and 6.
Noah got at least one 2.
Noah's score: 0
Press <enter> to continue ...
*******James's turn********
Scores: 2, 5, and 6.
James got at least one 2.
James's score: 0
Press <enter> to continue ...
*******Noah's turn********
Scores: 1, 3, and 6.
Noah's score: 10
(p)ass or (r)oll? r
Scores: 5, 4, and 3.
Noah's score: 22
*******James's turn********
Scores: 4, 2, and 6.
James got at least one 2.
James's score: 0
Press <enter> to continue...
Noah wins with a score of 22
Example 5
8+
@
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 3 steps with 2 images
Knowledge Booster
Background pattern image
Similar questions
- Carpet Calculator The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor (width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs 8ドル per square foot would cost 960ドル. First, you should create a class named RoomDimension that has two fields: one for the length of the room and one for the width. The RoomDimension class should have a method that returns the area of the room. (The area of the room is the room’s length multiplied by the room’s width.) Next you should create a RoomCarpet class that has a RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have a method that returns the total cost of the carpet. Figure 8-20 is a UML...arrow_forwardPYTHON programming solotion Develop a program that allows the user to enter a start value of 1 to 4, a stop value of 5 to 12 and a multiplier of 2 to 8. The program must display a multiplication table with results using these values. For example, if the user enters a start value of 3, a stop value of 7 and a multiplier value of 3, the table should be displayed as follows: Multiplication Table 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 additionally Each multiplication problem must be displayed with a problem number. The program must prompt the user to enter an answer to each of the multiplication problems. The correct answer should be displayed after the user enters an answer. A message should be displayed informing the user that the answer entered was correct or incorrect followed by an appropriate motivating comment. A running record of the number of correct and incorrect responses must be kept. After all the problems have been presented the user must be informed of...arrow_forwardJava problem First-Player Advantage Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: roll - If the player rolls a 1: the player scores nothing and it becomes the opponent's turn. 2 - 6: the number is added to the player's turn total and the player's turn continues. hold - The turn total is added to the player's score and it becomes the opponent's turn. Problem: There is an advantage to going first in Pig, but how big an advantage is it for "hold at 20 or goal" play? We wish to estimate the probability of a first-player win with a hold-at-20-or-goal play policy. Simulate a given number of two-player Pig games where a player rolls until a 1 ("pig") is rolled, or the turn total is greater than or equal to 20, or the...arrow_forward
- Part 3: Looping while(x<y) { If(z<0){ x=x+a; } Else{ x=x+z; z= -z } x=x+1; } Instructor Example 1: user input: x=5, y=2, z=5, a=5 x y z a Instructor Example 2: user input: x=2, y=13, z= -1, a=4 x y z a Looping Test Case 1: user input: x=2, y=18, z=10, a=2 x y z a Looping Test Case 2: user input: x=1, y=6, z=0, a=10 x y z aarrow_forward9. Trivia Game In this programming exercise, you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point. After answers have been selected for all the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner. To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data: A trivia question Possible answer 1 Possible answer 2 Possible answer 3 Possible answer 4 The number of the correct answer (1, 2, 3, or 4) The Question class also should have an appropriate _...arrow_forwardRock, Paper, Scissors Game Create a application using (C#) in Microsoft Visual Studio that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows.1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you use clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules: •If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)•If one player chooses scissors and the other player chooses paper, then scissors wins....arrow_forward
- Installation of a Shopee Billboard Max. score: 100 You are installing a billboard and want it to be at the maximum height. The billboard will have two steel supports, one on each side. The height of each steel bracket must be equal. You have a number of rebar rods that can be welded together. For example, if the bars are of length 1, 2, and 3, they can be welded together to form a length of 6 brackets. Return the maximum possible installation height of the billboard. Return 0 if the billboard cannot be installed.arrow_forwardRock, Paper, Scissors Game - MUST BE WRITTEN IN PSEUDOCODEarrow_forwardStart myNum RANDOM(1,10) false true myNum> 8 DISPLAY("Done") DISPLAY(myNum) 身arrow_forward
- Microwaves / Radio Waves If a scientist knows the wavelength of an electromagnetic wave she can determine what type of radiation it is. Write a program that asks for the wavelength in meters of an electromagnetic wave and then displays what that wave is according to the following chart. (For example, a wave with a wavelength of 1E-10 meters would be an X-ray.) 1x 10-11 1 x 10-8 4 x 10-7 7x 10-7 1x 10-3 1 x 10-2 Gamma Rays. X Rays Ultraviolet Visible Light Infraredarrow_forwardAdd Fractions problem: create in a sandbox environment. Directions: In this program you will ask the user for 4 integers that represtent two fractions. First ask for the numerator of the first and then the denominator. Then ask for the numerator and denominator of the second. Your program should add the two fractions and print out the result. For example: a sample program run might look like this, Numerator One: 1 Denominator One: 2 Numerator Two: 2 Denominator Two: 5 The sum is 9/10 //remember if you have two fractions, the following formula should be used: a/b + c/d = (a*d +b*c) / b* d public class MyProgram { public static void main(String[] args) { //Ask the user for 4 numbers. (don't forget to import your Scanner class) //create your final numerator //create your final denominator //print out your result like the example abovearrow_forwardJava:arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY