Question

Create a Dice Game: PYTHON This game is between two people. They will roll a pair...

Create a Dice Game: PYTHON

This game is between two people. They will roll a pair of dice each 10 times. Each roll will be added to a total, and after 10 rolls the player with the highest total will be the Winner!

  1. You will use the RANDOM class RANDRANGE to create a random number from 1 to 6.
  2. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice.
  3. You must have a Function for EACH die face that will be called with the Random number (i.e.; if 2 is the random number, the function that draws the die face with two dots will be called.  
  4. Since there are TWO die per roll, TWO die faces will need to be created.  
  5. The timer can be used to have the window display for a short period of time and then close the GUI window.  
  6. The numbers will chosen at random will be added to each player's total.
  7. You'll need to use a loop to loop 10 times for each round having each player roll the dice (loop type is your choice).
  8. Display the totals and who the winner is at the end of the game (10 rolls) by displaying in a table format:

DICE GAME

Player 1 Player 2
------------------------------------------
1) 10 8

2) 18 18
3) 22 24
4) 29 30
5) 38 39
6) 49 42
7) 55 51
8) 62 60
9) 70 69
10) 79 78

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey here is your program:-->

from sys import exit
import random
import time

#setting range of numbers for the die
min = 1
max = 6

#variables to hold dice values
x = 0
y = 0
x2= 0
y2= 0

player_name = input ("Enter your player1 name please: ")
player2_name = input ("Enter your player2 name : ")
Cap = player_name.upper()
Cap2=player2_name.upper()

loopcntrol=0
#arrays to store the scores in each round
player1 =[0,0,0,0,0,0,0,0,0,0]
player2=[0,0,0,0,0,0,0,0,0,0]


roll_again = "yes"
while roll_again == "yes":
if roll_again == "no":
exit(0)
if loopcntrol==10: #caz this loop will be run 10 times
break
print
print ("Player1 Turn")
print
time.sleep(1)
print ("Rolling the die...")
  
time.sleep (2)

x = random.randrange(min, max)
y = random.randrange(min, max)

def dice (m):
if m == 1:
print ("""
_________
| |
| |
| * |
| |
|_________| """)

elif m == 2:
print ("""
_________
| |
| * |
| |
| * |
|_________| """)
  
elif m == 3:
print ("""
_________
| |
| * |
| * |
| * |
|_________| """)
  
elif m == 4:
print ("""
_________
| |
| * * |
| |
| * * |
|_________| """)
  
  
elif m == 5:
print ("""
_________
| |
| * * |
| * |
| * * |
|_________| """)
  
  
elif m == 6:
print ("""   
_________
| |
| * * |
| * * |
| * * |
|_________| """)

dice (x)
dice(y)

print
time.sleep(1)
print
print ("Player2 Turn")
time.sleep(1)
print
print ("Rolling the die")
time.sleep(2)

x2 = random.randrange(min, max)
y2 = random.randrange(min, max)
  
dice(x2)
dice(y2)
time.sleep(1)

#will store indidual round dice vlaues
player1[loopcntrol]=x+y
player2[loopcntrol]=x2+y2

loopcntrol=loopcntrol+1

#calculatig(adding) the scores of each round for generating final scoreboard
for j in range(10):
if(j==0):
print
else:
player1[j]=player1[j]+player1[j-1]
player2[j]=player2[j]+player2[j-1]


# We set the condition of win, loss

if player1[9] == player2[9]:
print
print ("Ah! It's a draw.")
time.sleep(1)
  
elif player1[9] > player2[9]:
print
print ("Congrats! player1 Won"), Cap
time.sleep(1)
  
elif player1[9] < player2[9]:
print
print ("Sorry! Player1 Lost. Try again"), Cap
time.sleep(1)

print ("Rolls Player1 Player2")
for j in range(10):
print ('%-7i%-7i%-7i' % (j+1,player1[j],player2[j]))

Add a comment
Know the answer?
Add Answer to:
Create a Dice Game: PYTHON This game is between two people. They will roll a pair...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

  • Write a flowchart for a 2-dice game. This game will roll the two dice together for...

    Write a flowchart for a 2-dice game. This game will roll the two dice together for 100 times. In each time, it will display the face values from both dice. The program will count how many times (out of these 100 attempts) did the two dice generate a total point of 10 or above, and display the result at the end. In a word document, PPT file or a PDF file.

  • Write a Java pseudocode for a 2-dice game. This game will roll the two dice together...

    Write a Java pseudocode for a 2-dice game. This game will roll the two dice together for 100 times. In each time, it will display the face values from both dice. The program will count how many times (out of these 100 attempts) did the two dice generate a total point of 10 or above, and display the result at the end. In a word document, PPT file or a PDF file.

  • 1 point) Three brothers play a game with a pair of fair (six-sided) dice. Scott will...

    1 point) Three brothers play a game with a pair of fair (six-sided) dice. Scott will win if the sum of the dice is 3, Dave will win if 9, and Jim if 11 They will roll the die until a winner is declared Part (c) Realizing this, theoretically, is a game that could go on forever..the three brothers decide that if no winner has been decided in three rolls or "turns" Scott will be deemed the winner. Let Y...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...

  • The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

    The Rules of Pig 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...

  • The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values...

    The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • A dice game is played with two distinct 12 sided dice. It costs $3 to roll...

    A dice game is played with two distinct 12 sided dice. It costs $3 to roll the pair of dice one time. The payout scheme is as follows 1. Sum of 13 pays $10 Sum of 11 or 15 pays $6 Sum of 7, 9, 17, or 19 pays $3 Any other roll doesn't pay. What is the expected gain/loss after playing the game one time? A "fair" game is one in which the expected gain/loss after playing once is...

  • using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player...

    using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player plays against the house. The game starts with the player throwing a pair of standard, six-sided dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3, or 12, the player loses. For all other roll values, the player will repeatedly roll the pair of dice until either she rolls the initial value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT