Overview
Module 5 Assignment 1 features the design of pseudocode to support a Python program that requires coordination between the control structures and modules of two programs. This lab asks you to write pseudocode that plans the program’s logic before you write the program in Python in the next assignment. You will turn in only the pseudocode for the two modules for M5 Assignment 1.
Instructions
Write pseudocode for a Python program that makes 100 dice rolls with a single 6-sided die and displays the number of times each side appeared. Turn in the two modules for the pseudocode for the following instructions. The following steps describe what we want our two program modules to do.
Before proceding, download the files dice.py, dog.py, dog_new.py and M5Lab2dice_hist.py, as all will be referenced in your assignments this week. To find these files, reference the folder Module 5>Assignments>Exercises. These files were also in the zip file you downloaded in Module 1.
Requirements for Your M5 Assignment 1 Pseudocode for Program Integration
For the first module, write the pseudocode to process these tasks:
(Note: lines beginning with # are comments with tips for you)
- From the random module import randint to roll each die randomly
- # in pseudocode, import a random function
- # the name is helpful for the next M5-2 assignment
- Define a class called Dice
- In Python, the syntax has a colon after it: class Dice():
- In pseudocode, you can specify it generally or be specific
- Under the class declaration, list the attributes. Here are some tips:
- # attributes are what we know about a single die (dice is plural)
- # self is the first attribute in Python and must always appear first
- # add a num_sides attribute and to set it to 6 for the 6 sides on the dice
- Define a method for roll(self)
- # it describes what happens when we roll a single die
- # in the code, it will look like this example
- def __init__(self, dice_sides=6):
- # in pseudocode, we do not worry about the punctuation
- # just list it as part of your logic
- Under roll(self), return a random int value between 1 and self.dice_sides
- Save this file as M5Lab1ii – you can save it as MS Word or a text file.
For the second module, write the pseudocode to complete these tasks:
- In the same M5Lab1ii file, start a second module below the first module.
- From a new dice module, import our Dice class
- Create a 6-sided die by using assignment # for example: dice = Dice()
- Create an empty results list
- Write a for statement that takes each roll_num in range() and rolls it 100 times
- Set the value of result to dice.roll()
- For each roll and append it to the results list using your list’s name and .append() with the variable for each dice roll inside the parameters for append(). For example:
- # yourlistname.append(result)
- Refer to the name of your list within the print() parameter to print the results.
- 100 dice rolls for the values 1-6 appear in a list on the Python shell.
- Save the two modules in M5Lab1ii – you can save it as MS Word or a text file.
How to Complete Your M5 Assignment 1 Pseudocode for Program Integration
- Save your M5Lab1ii (ii= your initials). [example for someone with the initials cc: M5Lab1cc.py]
- Upload the M5Lab1ii document with two modules to M5 Assignment 1 Pseudocode for Python Program Integration Assignment Submission Folder. See the Schedule in the Syllabus Module for due dates. Review the Rubric attached to the Assignment Submission Folder for grading information.