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:

  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()
  4. # variable_name = Class()
  5. Declare an empty list called results
  6. Declare an empty frequencies list for the tracking how often each die value appears
  7. Declare a variable frequency and assign it to results.count(value)
  8. # Tracks the number of times each value from 1-6 is rolled
  9. print the frequencies # the format is print(listname)
  10. Bar chart: declare a variable hist and assign it the value pygal.Bar()
  11. Declare a hist.title variable and set the value to the following
  12. Your Name - Results of 1000 6-Sided Dice Rolls
  13. Replace "Your Name" with your name
  14. Declare a hist.x_title and set the value to Result using a string
  15. Declare a hist.y_title and set the string value to "How Often Did We Roll a 1, 2, 3, 4, 5, or 6?"
  16. # Tip: do not copy the string values surrounded by quotes from A MS Word file.
  17. # They use the wrong quotation symbols. Retype the quotation marks in Python.
  18. Save your M5Lab2dice_hist.py file into the same folder as dice.py
  19. # Both program files must be in the same folder
  20. 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.
  21. Open the folder with your labs in it
  22. The results and frequencies from 1000 rolls appear in a hist.render_to_file called "dice_barchart.svg"
  23. Drag the dice_barchart.svg file from your folder to a Web browser window to see your bar chart
  24. 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!