# 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
icon
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:

  1. Roll the dice 1000 times
  2. Do not print the results
  3. Instead, print the frequencies from a list called frequencies[]
    1. Frequencies are the number of times each number appears
  4. Add the titles to your bar chart
    1. # They are string values that appear at the top
    2. # List the titles for the x axis and the y axis of your chart
    3. # See the example in the code to support your pseudocode
  5. Render the chart to appear in a “dice_barchart.svg” file
  6. Add your name to the chart’s title
  7. Test your chart by dragging the file dice_barchart.svg into any Web browser window
  8. If you see your bar chart with 6 columns, examine it
    1. Hover your cursor over each column to see the values for 1000 dice rolls
  9. Save your pseudocode as M5Lab2ii.docx

Python code - Revise module 2 in M5Lab2dice_hist.py to add these steps:

  1. import Pygal # Pygal draws the bar chart or histogram for you
  2. import the Dice class # from dice import Dice
  3. declare the variable dice and assign the value to the class name Dice()
    1. # variable_name = Class()
  4. Declare an empty list called results
  5. Declare an empty frequencies list for the tracking how often each die value appears
  6. Declare a variable frequency and assign it to results.count(value)
    1. # Tracks the number of times each value from 1-6 is rolled
  7. print the frequencies # the format is print(listname)
  8. Bar chart: declare a variable hist and assign it the value pygal.Bar()
  9. Declare a hist.title variable and set the value to the following
    1. Your Name - Results of 1000 6-Sided Dice Rolls
    2. Replace “Your Name” with your name
  10. Declare a hist.x_title and set the value to Result using a string
  11. Declare a hist.y_title and set the string value to "How Often Did We Roll a 1, 2, 3, 4, 5, or 6?"
from first_module import Dice
result = []
for i in range(100):
dice = Dice()
result.append(dice.rol1())
print("Result : \n",result)
Transcribed Image Text:from first_module import Dice result = [] for i in range(100): dice = Dice() result.append(dice.rol1()) print("Result : \n",result)
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)
Transcribed Image Text: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)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education