# yahtzee.py import numpy as np import random # ------------------------------------------------- # Computer Science, Project 14 # November 14, 2017 # Partner 1 Name, Partner 2 Name # ------------------------------------------------- # Describe the contributions you and your partner # made to your solution. # ------------------------------------------------- def roll_dice(roll): """A function that simulates rolling 5 dice""" for i in range(len(roll)): roll[i] = random.randint(1, 6) return roll def count_outcomes(results): """A function that determines how many 1s, 2s, etc. were rolled""" counts = np.zeros(7, dtype=np.int16) for die in results: counts[die] += 1 return counts # ------------------------------------------------- # Your solution goes here # ------------------------------------------------- how_many = 5000 yahtzees = 0 full_houses = 0 large_straights = 0 roll = np.zeros(5, dtype=np.int16) for i in range(how_many): results = roll_dice(roll) if is_it_yahtzee(results): yahtzees += 1 elif is_it_full_house(results): full_houses += 1 elif is_it_large_straight(results): large_straights += 1 print("Number of Rolls:", how_many) print("---------------------") print("Number of Yahtzees:", yahtzees) print("Yahtzee Percent:", "{:.2f}%\n".format(yahtzees * 100 / how_many)) print("Number of Full Houses:", full_houses) print("Full House Percent:", "{:.2f}%\n".format(full_houses * 100 / how_many)) print("Number of Large Straights:", large_straights) print("Large Straight Percent:", "{:.2f}%".format(large_straights * 100 / how_many))