Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in this lab, please do it perfectly as required in the output. Please use the below given function to do the program.

I need help in this lab, please do it perfectly as required in the output. Please use the below given function to do the program.

image text in transcribed

image text in transcribed

image text in transcribed

import numpy as np import random import matplotlib.pyplot as plt # ------------------------------------------------- # CSCI 127, Lab 9 # January ???, 2021 # Your Name # ------------------------------------------------- class Die: def __init__(self, sides): """A constructor method to create a die""" self.sides = sides def roll(self): """A general method to roll the die""" return random.randint(1, self.sides) # ------------------------------------------------- class Yahtzee: def __init__(self, sides): """A constructor method that can record 5 dice rolls""" self.rolls = np.zeros(5, dtype=np.int16) self.sides = sides def roll_dice(self): """A general method that rolls 5 dice""" for i in range(len(self.rolls)): self.rolls[i] = Die(self.sides).roll() def count_outcomes(self): """A helper method that determines how many 1s, 2s, etc. were rolled""" counts = np.zeros(self.sides + 1, dtype=np.int16) for roll in self.rolls: counts[roll] += 1 return counts # ------------------------------------------------- def graph_yahtzee_data(data): pass def main(how_many): ## Part 1 low_rolls = 0 three_of_a_kinds = 0 large_straights = 0 game = Yahtzee(8) # 8-sided dice for i in range(how_many): game.roll_dice() if game.is_it_low_roll(): low_rolls += 1 elif game.is_it_three_of_a_kind(): three_of_a_kinds += 1 elif game.is_it_large_straight(): large_straights += 1 print("Number of Rolls:", how_many) print("---------------------") print("Number of Low Rolls:", low_rolls) print("Percent:", "{:.2f}% ".format(low_rolls * 100 / how_many)) print("Number of Three of a Kinds:", three_of_a_kinds) print("Percent:", "{:.2f}% ".format(three_of_a_kinds * 100 / how_many)) print("Number of Large Straights:", large_straights) print("Percent:", "{:.2f}%".format(large_straights * 100 / how_many)) ## Part 2 data = [low_rolls, three_of_a_kinds, large_straights] graph_yahtzee_data(data) # ------------------------------------------------- main(20000) 

Lab 9: NumPy and Matplotilib Logistics Due: Wednesday, January 6th no later than 11:59 p.m. Partner Information: You may complete this assignment individually or with exactly one partner. Submission Instructions (working alone): Upload your solution (py file), entitled YourFirstName-YourLastName-Lab9.py to the BrightSpace(D2L) Lab 9 Dropbox. Submission Instructions (working with a partner): Upload your solution -py file), entitled Your FirstName-YourLastName-PartnerFirstName-PartnerLastName-Lab9.py to the BrightSpace(D2L) Lab 9 Dropbox Deadline Reminder: Late passes can be used on this assignment. However, if you do not use a late pass and submit it past the deadline, you submission will lose some points (see late assignment policy). After 48 hours, the dropbox will close and you will no longer be able to submit In order to complete this lab, you will need to understand Numpy Arrays Matplotlib Object Oriented Programming Background In a modified game of Yahtzee, five eight-sided dice are rolled once. For this assignment, you will simulate this modified game of Yahtzee to determine how likely certain outcomes are. In this modified version of Yahtzee, a Low Roll occurs when each of the five dice is either a 1 or an 2. For example, 1-1-1-1-1 or 2-2-1-2-1. In this modified version of Yahtzee, a Three of a kind occurs when three of the dice show the same number. The other two dice must not show this number and must also be different from one another. For example, 4-7-4-4-2 but not 4-7-4-4-7. In this modified version of Yahtzee, a large straight occurs when the five numbers can be arranged consecutively (for example, 1-3-4-2-5 or 5-7-4-6-3). Hint: the numpy library contains a sort function. Part 1: Numpy Download lab11.py, rename it according to the instructions above, and make sure you understand it. Take the program above and modify it by adding the missing methods such that when the program is run, it might produce this output. Note that your percents may be slightly different due to random values being generated each time you run the program, but your percents should still be pretty close. Do not change any of the existing Python code. Part 2: Matplotlib coming soon Grading - 10 points 3 points - Low Rolls are identified correctly. 3 points - Three of a Kinds are identified correctly. 4 points - Large straights are identified correctly. Number of Rolls: 20000 Number of Low Rolls: 18 Percent: 0.09% Number of Three of a kinds: 1995 Percent: 9.97% Number of Large Straights: 261 Percent: 1.30%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions