Question

Write a program which implements a dice game. Name your program file YourUsernameA105.py, e.g. afer023A1Q5.py. The aim of the game is to reach a score as close as possible to 100 (but not over 100) in three rounds. Each round consists of throwing five random dice, the user then chooses two of the dice values where the two dice values chosen form a two digit score which is added to the users current total, e.g., if the user first chooses a dice with the value 3 and then a dice with the value 5, 35 is added to the users total (the first dice chosen is the tens digit and the second dice chosen is the units digit). The random dice are displayed with one space between each dice, e.g., Your dice: 3 5 341 and to choose the dice the user enters a number 1, 2, 3, 4 or 5 indicating which of the five dice they wish to choose, i.e., the position of the dice (not the value of the dice). This process is repeated three times. Below is the statement which initialises the users current score: current total = 0
media%2Fe76%2Fe76b1548-7718-4fe4-87a4-7a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Program:

""" Dice Game """
from random import randint

# Set to 0
current_total = 0

# Printing headers
print('*'*45)
print("REACH 100 IN THREE ROUNDS!   Initial total: 0")
print('*'*45)

# Playing three rounds
for i in range(3):
   print("\nRound " + str(i+1))
   # List to hold outcomes
   diceRoll = []
   # Throwing five dices
   for j in range(5):
       diceRoll.append(randint(1, 6))
   # Printing outcomes
   print("Your dice: ", end = " ")
   # Printing five dices values
   for j in range(5):
       print(diceRoll[j], end=" ")
   # Reading input from user
   tens = int(input("\n Tens? "))
   units = int(input(" Units? "))
  
   # Calculating dice value
   diceValue = diceRoll[tens-1] * 10 + diceRoll[units-1]
  
   # Adding to total
   current_total = current_total + diceValue
  
   print("Dice Value: " + str(diceValue) + "\n\nYour current total: " + str(current_total) + "\n")
  
  
print("\n" + '*'*21)
print("Your final score: " + str(current_total))
print('*'*21)


____________________________________________________________________________________

Sample Run:

RESTART: D:\Python\DiceGame100.py REACH 100 IN THREE ROUNDS! Initial total: 0 Round 1 Your dice 3 6 4 3 1 Tens? 1 Units? 2 Dice Value: 36 Your current total: 36 Round2 Your dice 5 5 5 3 4 Tens? 3 Units? 1 Dice Value: 55 Your current total: 91 Round 3 Your dice 3 4 2 6 1 Tens? 5 Units? 3 Dice Value: 12 Your current total: 103 Your final score 103

Add a comment
Know the answer?
Add Answer to:
Write a program which implements a dice game. Name your program file 'YourUsernameA105.py, e.g. afer023A1Q5.py. The...
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
  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • Write a class called OneRoundOneRollYahtzee. The program should behave the same as the InputOrGenerateDiceRolls (which is...

    Write a class called OneRoundOneRollYahtzee. The program should behave the same as the InputOrGenerateDiceRolls (which is as follows: InputOrGenerateDiceRolls program should ask the user whether the user prefers 1) to roll his/her own dice, 2) use computer-generated dice rolls, or 3) quit the program. If the user prefers to roll his/her own dice, the program should prompt the user to enter 5 digits in the range from 1-6 separated by spaces in any order with duplicates allowed. However, if the...

  • Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the...

    Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the user to enter the answer of multiplying two one-digit random integers.  If the user enters a correct answer, a message will be displayed at the bottom of the frame, and the text field will be cleared.  If the user enters a wrong answer, a message will be displayed at the bottom of the frame asking for another answer.  If the user...

  • Write a program in the Codio programming environment that allows you to play the game of...

    Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage.  We may rerun all tests within Codio before grading your program. Please see...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game....

    Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game. It is played through dice. Rule for scoring The player who rolls higher number gets one point. If both players roll the same number, it is considered a draw and no one gets a point. Dice Specification There are two kinds of dice: normal die, represented by Die class. loaded die, represented by the loadedDie class. Classes Die class Die class has a member...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with...

    JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with individual digits from 0 to 9 inclusive. (i.e. 12345, 09382, 33044, etc.) The player then tries to guess the number. With each guess the program displays two numbers, the first is the number of correct digits that are in the proper position and the second number is the sum of the correct digits. When the user enters the correct five-digit number the program returns...

  • Assignment 2 – The two player game of Poaka The game of Poaka is a dice...

    Assignment 2 – The two player game of Poaka The game of Poaka is a dice game played by two players. Each player takes turns at rolling the dice. At each turn, the player repeatedly rolls a dice until either the player rolls a 1 (in which case the player scores 0 for their turn) or the player chooses to end their turn (in which case the player scores the total of all their dice rolls). At any time during...

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