Question: 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
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?"
- # Tip: do not copy the string values surrounded by quotes from A MS Word file.
- # They use the wrong quotation symbols. Retype the quotation marks in Python.
- Save your M5Lab2dice_hist.py file into the same folder as dice.py
- # Both program files must be in the same folder
- Run your M5Lab2dice_hist.py file and see if it lists in the Python shell the number of times each number appeared on the dice rolls.
- Open the folder with your labs in it
- The results and frequencies from 1000 rolls appear in a hist.render_to_file called "dice_barchart.svg"
- Drag the dice_barchart.svg file from your folder to a Web browser window to see your bar chart
- Hover over the columns to see the frequencies appear
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
