# For module1 import random class Dice: def __init__(self,dice_side = 6): self.num_sides = dice_side def roll(self): return random.randint(1,self.num_sides) # For module2 from first_module import Dice result = [] for i in range(100): dice = Dice() result.append(dice.roll()) print("Result : \n",result)
# For module1 import random class Dice: def __init__(self,dice_side = 6): self.num_sides = dice_side def roll(self): return random.randint(1,self.num_sides) # For module2 from first_module import Dice result = [] for i in range(100): dice = Dice() result.append(dice.roll()) print("Result : \n",result)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
# For module1
import random
class Dice:
def __init__(self,dice_side = 6):
self.num_sides = dice_side
def roll(self):
return random.randint(1,self.num_sides)
# For module2
from first_module import Dice
result = []
for i in range(100):
dice = Dice()
result.append(dice.roll())
print("Result : \n",result)
Pseudocode - Revise module 2 in your pseudocode to add these steps:
- Roll the dice 1000 times
- Do not print the results
- Instead, print the frequencies from a list called frequencies[]
- Frequencies are the number of times each number appears
- Add the titles to your bar chart
- # They are string values that appear at the top
- # List the titles for the x axis and the y axis of your chart
- # See the example in the code to support your pseudocode
- Render the chart to appear in a “dice_barchart.svg” file
- Add your name to the chart’s title
- Test your chart by dragging the file dice_barchart.svg into any Web browser window
- If you see your bar chart with 6 columns, examine it
- Hover your cursor over each column to see the values for 1000 dice rolls
- Save your pseudocode as M5Lab2ii.docx
Python code - Revise module 2 in M5Lab2dice_hist.py to add these steps:
- import Pygal # Pygal draws the bar chart or histogram for you
- import the Dice class # from dice import Dice
- declare the variable dice and assign the value to the class name Dice()
- # variable_name = Class()
- Declare an empty list called results
- Declare an empty frequencies list for the tracking how often each die value appears
- Declare a variable frequency and assign it to results.count(value)
- # Tracks the number of times each value from 1-6 is rolled
- print the frequencies # the format is print(listname)
- Bar chart: declare a variable hist and assign it the value pygal.Bar()
- Declare a hist.title variable and set the value to the following
- Your Name - Results of 1000 6-Sided Dice Rolls
- Replace “Your Name” with your name
- Declare a hist.x_title and set the value to Result using a string
- Declare a hist.y_title and set the string value to "How Often Did We Roll a 1, 2, 3, 4, 5, or 6?"
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education