Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the game, the player is allowed to keep any number of the five dice (from zer

ID: 3723994 • Letter: I

Question

In the game, the player is allowed to keep any number of the five dice (from zero to all five), and throw the remaining dice again. The player is then allowed to keep any of the five dice and throw the remaining dice yet again. (The player is even allowed to rethrow dice he or she kept on the previous throw.) The best score in the game is called a Yahtzee, which happens when the player obtains the same number on all five dice. For example, the player might throw 2, 2, 4, 5, 6. The player might choose to keep the 2, 2 and throw the other three dice again. In the second throw, the player obtains 1, 2, 3. The player keeps the 2 (making three 2’s) and rethrows the remaining two dice. If those dice come up 2, 2, the player has made Yahtzee. Write a program to simulate Yahtzee. Assume the player is trying to achieve Yahtzee. What is the estimated probability of achieving Yahtzee? (Hint: the exact value is approximately 5%.)
The program needs to be in python In the game, the player is allowed to keep any number of the five dice (from zero to all five), and throw the remaining dice again. The player is then allowed to keep any of the five dice and throw the remaining dice yet again. (The player is even allowed to rethrow dice he or she kept on the previous throw.) The best score in the game is called a Yahtzee, which happens when the player obtains the same number on all five dice. For example, the player might throw 2, 2, 4, 5, 6. The player might choose to keep the 2, 2 and throw the other three dice again. In the second throw, the player obtains 1, 2, 3. The player keeps the 2 (making three 2’s) and rethrows the remaining two dice. If those dice come up 2, 2, the player has made Yahtzee. Write a program to simulate Yahtzee. Assume the player is trying to achieve Yahtzee. What is the estimated probability of achieving Yahtzee? (Hint: the exact value is approximately 5%.)
The program needs to be in python In the game, the player is allowed to keep any number of the five dice (from zero to all five), and throw the remaining dice again. The player is then allowed to keep any of the five dice and throw the remaining dice yet again. (The player is even allowed to rethrow dice he or she kept on the previous throw.) The best score in the game is called a Yahtzee, which happens when the player obtains the same number on all five dice. For example, the player might throw 2, 2, 4, 5, 6. The player might choose to keep the 2, 2 and throw the other three dice again. In the second throw, the player obtains 1, 2, 3. The player keeps the 2 (making three 2’s) and rethrows the remaining two dice. If those dice come up 2, 2, the player has made Yahtzee. Write a program to simulate Yahtzee. Assume the player is trying to achieve Yahtzee. What is the estimated probability of achieving Yahtzee? (Hint: the exact value is approximately 5%.)
The program needs to be in python

Explanation / Answer

Code:

# Computes the probability of the various hands in Yahtzee.

import random
count_three=0
count_four=0
count_full=0
count_small=0
count_large=0
count_yah=0

def roll_dice():
'''Returns 5 randomly rolled dice.'''
dice = []
for i in range(5):
dice += [random.randint(1,6)]
dice2=dice.sort()
print(dice)
return dice

def three_of_a_kind(dice):
'''Returns True or False if the dice are three of a kind.'''
global count_three
dice=set(dice)
if (len(dice)==3):
   count_three+=1
else:
   pass

def four_of_a_kind(dice):
''' Returns True or False if the dice are four of a kind. '''
global count_four
dice.sort()
dice2=set(dice)
if (len(dice2)==2):
   if (dice[2]==dice[3]):
       count_four+=1
   else:
       pass
else:
   pass

def full_house(dice):
'''Returns True of False if the dice are a full house.'''
global count_full
dice.sort()
dice2=set(dice)
if (len(dice2)==2):
   if (dice[2]!=dice[3]):
       count_full+=1
   else:
       pass
else:
   pass

def small_straight(dice):
''' Returns True or False if the dice represent a small straight. '''
global count_small
dice.sort()
dice1=dice[:4]
if (dice1 == (1,2,3,4) and dice[4]!=5):
count_small+=1
elif(dice1 == (2,3,4,5) and dice[4]!=6):
count_small+=1
else:
pass
       
def large_straight(dice):
''' Returns True or False if the dice represent a large straight. '''
global count_large
dice.sort()
if (dice == (1,2,3,4,5)):
count_large+=1
elif(dice == (2,3,4,5,6)):
count_large+=1
else:
pass
       
def yahtzee(dice):
''' Returns True or False if the dice represent Yahtzee'''
global count_yah
dice=set(dice)
if(len(dice)==1):
   count_yah+=1

def main():
'''The main block of your code.'''
total_rolls = 0.0
num_rolls=int(input("Number of Dice rolls: "))
for i in range( num_rolls):
dice=roll_dice()
three_of_a_kind(dice)
four_of_a_kind(dice)
full_house(dice)
small_straight(dice)
large_straight(dice)
yahtzee(dice)
percent_yahtzee = count_yah/num_rolls * 100
percent_fourofkind = count_four/num_rolls * 100
percent_largestraight = count_large/num_rolls * 100
percent_smallstraight = count_small/num_rolls * 100
percent_fullhouse = count_full/num_rolls * 100
percent_threeofkind = count_three/num_rolls * 100
  
print("Number of Dice rolls:" , + num_rolls)
print("Yahtzee: ", + percent_yahtzee)
print("Four of a kind: ", + percent_fourofkind)
print("Large straight: ", + percent_largestraight )
print("Small straight : ", + percent_smallstraight)
print("Full house: ", + percent_fullhouse)
print("Three of a kind: ", + percent_threeofkind)
return
  

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote