Question

In: Computer Science

For this problem, you will write a program in which the computer plays a dice game...

For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment.

PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution

Rules:

The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3, or 12 on the first roll (called “craps”), you lose (the “house” wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first roll, that sum becomes your “point”. To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value again). You lose by rolling a 7 before making your point.

Requirements:

When your program starts, give the player the option to “back out” of playing.

After every roll, ask the player if they want to continue. If they quit, exit the program gracefully with a message indicating they quit

Print appropriate messages (and end the game properly) when the player wins or loses, based on the rules provided above.

AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and dazzle us with...

  • Have at least 3 random witty/engaging messages that print automatically when the player is trying to get their “point”. Consider this the “house manager” trying to distract the player from winning.
    Example:

You rolled 2 + 3 = 5
Your Point is 5
Do you want to continue or quit (Q to quit) c
You rolled 1 + 1 = 2

House Manager: “Don’t quit your day job.”

Do you want to continue or quit (Q to quit) c
You rolled 4 + 2 = 6

House Manager: “Are you nervous? You look like you're sweating or just took a shower!”

Do you want to continue or quit (Q to quit) c
You rolled 2 + 3 = 5

You win!

For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment.

PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution

Rules:

The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3, or 12 on the first roll (called “craps”), you lose (the “house” wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first roll, that sum becomes your “point”. To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value again). You lose by rolling a 7 before making your point.

Requirements:

When your program starts, give the player the option to “back out” of playing.

After every roll, ask the player if they want to continue. If they quit, exit the program gracefully with a message indicating they quit

Print appropriate messages (and end the game properly) when the player wins or loses, based on the rules provided above.

AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and dazzle us with...

  • Have at least 3 random witty/engaging messages that print automatically when the player is trying to get their “point”. Consider this the “house manager” trying to distract the player from winning.
    Example:

You rolled 2 + 3 = 5
Your Point is 5
Do you want to continue or quit (Q to quit) c
You rolled 1 + 1 = 2

House Manager: “Don’t quit your day job.”

Do you want to continue or quit (Q to quit) c
You rolled 4 + 2 = 6

House Manager: “Are you nervous? You look like you're sweating or just took a shower!”

Do you want to continue or quit (Q to quit) c
You rolled 2 + 3 = 5

You win!

For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment.

PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution

Rules:

The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3, or 12 on the first roll (called “craps”), you lose (the “house” wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first roll, that sum becomes your “point”. To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value again). You lose by rolling a 7 before making your point.

Requirements:

When your program starts, give the player the option to “back out” of playing.

After every roll, ask the player if they want to continue. If they quit, exit the program gracefully with a message indicating they quit

Print appropriate messages (and end the game properly) when the player wins or loses, based on the rules provided above.

AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and dazzle us with...

  • Have at least 3 random witty/engaging messages that print automatically when the player is trying to get their “point”. Consider this the “house manager” trying to distract the player from winning.
    Example:

You rolled 2 + 3 = 5
Your Point is 5
Do you want to continue or quit (Q to quit) c
You rolled 1 + 1 = 2

House Manager: “Don’t quit your day job.”

Do you want to continue or quit (Q to quit) c
You rolled 4 + 2 = 6

House Manager: “Are you nervous? You look like you're sweating or just took a shower!”

Do you want to continue or quit (Q to quit) c
You rolled 2 + 3 = 5

You win!

Solutions

Expert Solution

import random

wittyMessage= ["House Manager: Don’t quit your day job.", "House Manager: Are you nervous? You look like you're sweating or just took a shower!", "House Manager: “Are you nervous? You look like hungry, go have some dinner!”"]

def roll_die():
   return random.randint(1,6)

def roll_dice():
   d1, d2 = roll_die(), roll_die()
   return d1, d2, (d1 + d2)

def main():
   (dice1,dice2,roll) = roll_dice()
  
   print('You rolled', dice1,'+',dice2,'=',roll)

   if roll == 7 or roll == 10:
       print('Natural, You win!')
   elif roll == 2 or roll == 3 or roll == 12:
       print('Craps! You lose!')
   else:
       print('You scored', roll,'points')
       mypoints = roll
      
       playerInput=input('Do you want to continue or quit (Q to quit or C to Continue)')
       if playerInput == 'Q':
          
           print('Thank you for playing')
           quit
       if playerInput == 'C' :
           reroll(mypoints)
      
      

def reroll(points):
  
   dice1 = random.randint(1,6)
   dice2 = random.randint(1,6)
   total = dice1 + dice2


   if total == points:
       print('You rolled', dice1, '+', dice2, '=', total)
       print(random.choice(wittyMessage))

       print('Congrats you win')
   elif total == 7:
       print('You rolled', dice1, '+', dice2, '=', total)
       print('Sorry you lose')
      
main()


Related Solutions

1. Write a program that plays a simple dice game between the computer and the user....
1. Write a program that plays a simple dice game between the computer and the user. When the program runs, it asks the user to input an even number in the interval [2..12], the number of plays. Display a prompt and read the input into a variable called ‘plays’ using input validation. Your code must ensure that the input always ends up being valid, i.e. even and in [2..12]. 2. A loop then repeats for ‘plays’ iterations. Do the following...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Write a program in Matlab where the program plays a hot and cold game. The user...
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
A gambler plays a dice game where a pair of fair dice are rolled one time...
A gambler plays a dice game where a pair of fair dice are rolled one time and the sum is recorded. The gambler will continue to place $2 bets that the sum is 6, 7, 8, or 9 until she has won 7 of these bets. That is, each time the dice are rolled, she wins $2 if the sum is 6, 7, 8, or 9 and she loses $2 each time the sum is not 6, 7, 8, or...
Sarah D's road manager plays a dice game with two dice. The six sides of on...
Sarah D's road manager plays a dice game with two dice. The six sides of on each die are numbered from 2 to 7. Define the random variable X to be the sum of the numbers on the up-face of the two dice when rolled. a. Construct table showing PDF and the CDF of the random variable X b. Calculate the mode of the distribution. c. Calculate the expected value of X. d. Calculate variance of X. e. Calculate P(4
This problem concerns the dice game craps. On the first roll of two dice, you win...
This problem concerns the dice game craps. On the first roll of two dice, you win instantly with a sum of 7 or 11 and lose instantly with a roll of 2,3, or 12. If you roll another sum, say 5, then you continue to roll until you either roll a 5 again (win) or roll a 7 (lose). How do you solve for the probability of winning?
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses...
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The script displays the prompt Guess a number between 1 and 1000 next to a text field. The player types a first guess into the text field and clicks a button to submit the guess to the script. If the player's guess is incorrect, your program should display...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT