Question

Complete each problem separately and perform in python. 1. Create a script that will roll five...

Complete each problem separately and perform in python.

1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex:

Hit enter to roll

1,4,3,6,6

Hit enter to roll

3,5,1,2,1

Hit enter to roll

4,3,4,2,6

2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print out the dice values and the total like this:

Hit enter to roll

5,4,2,3,1

Total score: 15

3. Write a script that allows the user to roll five dice. They will have two turns. On the first turn, they roll all five dice and then set one aside, keeping that die's value. Then, they roll the remaining 4 dice. Their final score is the sum of all 5 dice (the one they saved and the 4 they rolled in their second turn).

Hit enter to roll

You rolled

Die 1: 1

Die 2: 5

Die 3: 3

Die 4: 6

Die 5: 1

Which die would you like to keep? 4

You saved die 4 with a value of 6

Hit enter to roll the remaining dice

You rolled

Die 1: 2

Die 2: 2

Die 3: 3

Die 4: 3

Your total score is 16

4. Write a script where the user rolls 4 dice on time. They win if at least two dice have the same value. They lose if all the dice have different values. Example:

Hit enter to roll

You rolled

4,3,1,5

You Lose

5. Adapt exercise 4 so, instead of just rolling once, they user can play the game over and over.

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

1)

import random
i=1
while(i<=3):
strU = input("Hit enter to roll")
if(strU==''):
for x in range(5):
print(random.randint(1,6), end=' ')
print()
i=i+1

Output:

Hit enter to roll 3 6 2 4 5 Hit enter to roll 1 3 51 1 Hit enter to roll 6 1 2 4 4

Explanation: As we need to roll thrice, make a while loop to run three times. Now in each roll we need five dice roll so generate random numbers between 1 and 6

2)

Program:

import random
sumNum = 0
strU = print("Hit enter to roll")

if(strU==''):

for x in range(5):
num = random.randint(1,6)
print(num, end=' ')
sumNum = sumNum + num
print()
print("Total score:",sumNum)

Output:

media%2Fb54%2Fb546ae02-6854-4974-8eff-9c

Explanation: Here we need to roll just once, five dice hence a for loop to run 5 times and generate 5 random numbers between 1 and 6. Also we need the total score hence add all the numbers generated in each roll.

3)

Program:

import random

die = []
value = []
sumNum = 0

strU = input("Hit enter to roll")
if(strU==''):
print("You rolled")
for x in range(5):
num = random.randint(1,6)
print("Die",x+1,":",num)
die.append(x)
value.append(num)
  
print()
dieNum = int(input("Which die would you like to keep: "))
print()
print("You saved die",dieNum,"with value of",value[dieNum-1])

strU = input("Hit to enter remaining roll")
if(strU==''):
print("You rolled")
for x in range(4):
num = random.randint(1,6)
print("Die",x + 1,":",num)
sumNum = sumNum + num
  
total = sumNum + value[dieNum-1]
print("Tota score:",total)

Output:

Hit enter to roll You rolled Die 1: 6 Die 2 : 6 Die 3 1 Die 4 1 Die 5 4 ich die would you like to keep: 4 ou saved die 4 with

4)

Program:

import random

value = []

count
strU = input("Hit enter to roll")
if(strU==''):
print("You rolled")
for x in range(5):
num = random.randint(1,6)
print(num,end=' ')
value.append(num)
  
for x in range(5):
for y in range(5):
if(value[x]==value[y] and (x!=y)):
count = 1;
break;
print()
if(count == 1):
print("You win")
else:
print("You loose")

Output:

Hit enter to roll You 4155 4 You win rolled

5)

Program:

import random
value = []
ch='a'
count=0
while(not(ch=='q'or ch=='Q')):
strU = input("Hit enter to roll")
if(strU==''):
print("You rolled")
for x in range(5):
num = random.randint(1,6)
print(num,end=' ')
value.append(num)
  
for x in range(5):
for y in range(5):
if(value[x]==value[y] and (x!=y)):
count = 1;
break;
print()
if(count == 1):
print("You win")
else:
print("You loose")
ch = input("Want to play again, q to quit: ")

Output:

t enter to roll rolled 1 4 2 5 3 loose ant to play again, q to quit: a Hit enter to roll rolled ou 4644 1 You loose ant to pl

Add a comment
Know the answer?
Add Answer to:
Complete each problem separately and perform in python. 1. Create a script that will roll five...
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: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation...

    in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation program to estimate the winning chance of the Craps game. Craps is a popular dice game played in casinos. Here is how to play: Roll two dice. Each die has 6 faces representing values 1,2,3,4,5,and 6, respectively. Check the sum of 2 dice. If the sum is 2, 3, or 12 (called craps), you lose; if the sum is 7 or 11 (called natural),...

  • In python 3, Write a program in Python that simulates the roll of two dice. The...

    In python 3, Write a program in Python that simulates the roll of two dice. The first die is a 6-sided die. The second die is an 8-sided die. Generate a random number for a die and store it in variable number1. Generate a random number for a die and store it in variable number2. Note: Submit your code with the print("You rolled two dice:", number1, "and", number2) statement.

  • This is in C++. The program needs to show the points as well. The blue boxes...

    This is in C++. The program needs to show the points as well. The blue boxes show below are the output and it should look like that. Thanks (Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Roll two dice. Each die has six faces representing values 1, 2, ..., and 6, respectively. Check the sum of the two dice. If the sum is 2, 3,...

  • In the game of Yahtzee®, players roll five dice simultaneously to try to make certain combinations....

    In the game of Yahtzee®, players roll five dice simultaneously to try to make certain combinations. In a single turn, a player may roll up to three total times. On the first roll, the player rolls all five dice. On subsequent rolls, the player may choose to roll any number of the five dice ("keeping" dice by leaving selected unrolled dice on the table). If a player's first roll results in exactly three 5's (e.g., 2-5-5-3-5), what is the probability...

  • 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...

  • 1. You roll a pair of standard dice. Create the sample space for a single roll...

    1. You roll a pair of standard dice. Create the sample space for a single roll of the dice and use the sample space to compute the following probabilities. A. Create a sample space. B. P ( getting a 1 on the first die or getting a 5 on the second die) C. P (Sum of the dice = 10) D. P ( getting a 3 on the second die given that you got a 2 on the first die)...

  • 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, can you help me solve these questions? Thanks! 1- Roll a dice (get a random...

    Please, can you help me solve these questions? Thanks! 1- Roll a dice (get a random number from 1 to 6) 2-Print value of the dice 3- Keep track of running total points(display of points) 4-Ask the user to continue (y/n) 5- If the user gets 21 points, print " bingo" 6- If the user more than 21 points, print "sorry you lose" 7- If the user decides to stop the game, print his final points.

  • 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! You will use the RANDOM class RANDRANGE to create a random number from 1 to 6. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice. You must...

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