My Paper Writer » Essay Blog » Research Paper Help » Module 5 Assignment 2: Modular Design of Two Python Programs

Module 5 Assignment 2: Modular Design of Two Python Programs


In Module 5 Assignment 2, modify your pseudocode to make 1000 dice rolls, and instead of displaying the list, use Pygal to display the results in a bar chart.


M5 Assignment 2 uses both modules from M5-1 and asks you to modify the second module to increase the number of rolls to 1000, to calculate how frequently each number appears, and to display the results in a bar char, which is called a histogram in Pygal.

Some of the code is written for you, so review the two files for module 1 in and module 2 in file to see how the lab works. Some of the code is missing in

Read both program files to see what is missing. You will revise your pseudocode and revise the file.

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 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?”
    1. # Tip: do not copy the string values surrounded by quotes from A MS Word file.
    2. # They use the wrong quotation symbols. Retype the quotation marks in Python.
  12. Save your file into the same folder as
    1. # Both program files must be in the same folder
  13. Run your file and see if it lists in the Python shell the number of times each number appeared on the dice rolls.
  14. Open the folder with your labs in it
  15. The results and frequencies from 1000 rolls appear in a hist.render_to_file called “dice_barchart.svg”
  16. Drag the dice_barchart.svg file from your folder to a Web browser window to see your bar chart
  17. Hover over the columns to see the frequencies appear

Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) the dice_barchart.svg file, which displays the output as a bar chart, and 3) your Python program.

How to Complete Your M5 Assignment Modular Design of Two Python Programs

In the M5 Assignment 2 Modular Design of Two Python Programs Assignment Submission Folder:

  1. Upload
  2. Upload your pseudocode in M5Lab2ii.docx
  3. Upload your dice_barchart.svg files to M5 Assignment 2 Modular Design of Two Python Programs Assignment Submission Folder.
    1. You do not need to post unless you made changes to the class file.
    2. If you changed your Dice() class or its attributes, attach the changed files.

See the Schedule in the Syllabus Module for due dates. Review the Rubric attached to the Assignment Submission Folder for grading information.


Last Updated on August 9, 2019

Don`t copy text!