# This progran will sinu iate a game of Yahtzee? # Yahtzee? is a dice game that rolls flue dice # and gives a score based on what dice uere rolled # Obtain the package for randon nunbers inport randon...

# This progran will sinu iate a game of Yahtzee? # Yahtzee? is a dice game that rolls flue dice # and gives a score based on what dice uere rolled # Obtain the package for randon nunbers inport randon # These first two functions uill handle the dice rolling # 1hey are separated because one creates a list fron scratch, # the uther nodified its giuen list, and the second may # be called more often, since the player can reroll tuice def roll1 dice: rolls 5 dice, and return a list of Frequencies of each possible value' rolls- [81*7 print( Rolled:,end-' ') for repeat in range(5) dice randon.randint 1,6) print(dice,end-) rolls(dice] = rolls[dice] + 1 print() return rolls def sumcounts(counts) adds up the total of the dice, given the frequencies of each value total -0 for i in range(7) return total total i countsti] def three of a_kind (counts): "returns the total of all dice if at least three natch, ur zero other ise. if 3 in counts or in counts or 5 in counts: return sun counts(counts) else: return ? def fourof_a_kind counts): returns the total of all dice if at least Four match or zero otherwise if h in counts or 5in counts: return suncounts( counts - else: return 9 def yahtzee(counts): returns 30 if there are 2 of one nunber, or zero otheruise'"" if 2 in counts or in counts: return 30 else: return 9 def Ful1 house(counts): returns 30 if there are 2 of one nunber, and 3 of another if 2 in counts and 3 in counts: return 30 else: return def snall_straight (counts): returns 25 if there are at least consecutive values if [1,1,0,1,1] in counts[1:6]: return 25 else: return def large straight (counts): returns a0 if there are at least 5 consecutiue values if [1,1,1,1,1] in counts[1:]: return 30 else: return # Put the functions in a list and nanes then score-lower [three-of-a-kind, four of kind, full-house, = a snall straight. large straight, yahtzee, sum counts] name louer[Three of a Kind'Four of a Kind Snall Straight Large Straight. Fu11 House, ·Yahtzee. ' counts -roll dice) for i in range(7) print(f"nane_lower[i]:17score_lower[i] (counts):2" # Ask the user if they would like to play the sinulation again keep goingy while keep goingy keep going input( P1ay again (y/n)? ) if keep going- y roll dice) For i in range(7): print. (f..(name 1?uer[1] :17) {score-Inwer[1](counts) :2)") if keep going - 'n print Good bye!
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here