Question: 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

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)

  1. From the random module import randint to roll each die randomly
  2. # in pseudocode, import a random function
  3. # the name is helpful for the next M5-2 assignment
  4. Define a class called Dice
  5. In Python, the syntax has a colon after it: class Dice():
  6. In pseudocode, you can specify it generally or be specific
  7. Under the class declaration, list the attributes. Here are some tips:
  8. # attributes are what we know about a single die (dice is plural)
  9. # self is the first attribute in Python and must always appear first
  10. # add a num_sides attribute and to set it to 6 for the 6 sides on the dice
  11. Define a method for roll(self)
  12. # it describes what happens when we roll a single die
  13. # in the code, it will look like this example
  14. def __init__(self, dice_sides=6):
  15. # in pseudocode, we do not worry about the punctuation
  16. # just list it as part of your logic
  17. Under roll(self), return a random int value between 1 and self.dice_sides
  18. 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:

  1. In the same M5Lab1ii file, start a second module below the first module.
  2. From a new dice module, import our Dice class
  3. Create a 6-sided die by using assignment # for example: dice = Dice()
  4. Create an empty results list
  5. Write a for statement that takes each roll_num in range() and rolls it 100 times
  6. Set the value of result to dice.roll()
  7. 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:
  8. # yourlistname.append(result)
  9. Refer to the name of your list within the print() parameter to print the results.
  10. 100 dice rolls for the values 1-6 appear in a list on the Python shell.
  11. 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

  1. Save your M5Lab1ii (ii= your initials).[example for someone with the initials cc: M5Lab1cc.py]
  2. Upload the M5Lab1ii document with two modules to M5 Assignment 1 Pseudocode for Python Program Integration Assignment Submission Folder. See theSchedulein theSyllabusModulefor due dates. Review theRubricattached to the Assignment Submission Folder for grading information.

# Randomly rolls a 6-sided die

from random import randint

class Dice():

"""A class for a single six-sided die"""

def __init__(self, dice_sides=6):

"""A six-sided die."""

self.dice_sides = dice_sides

def roll(self):

"""Returns a random value between 1 and the number of sides."""

return randint(1, self.dice_sides)

from dog import Dog

# Here is your second dog

dog = Dog("Poe","Terrier","7")

print("My dog's name is " + dog.name.title() + ".")

print("My dog's breed is " + dog.breed.title() + ".")

print("My dog's age is " + dog.age + ".")

dog.sit()

dog.stay()

# Here is an example of our Dog() class.

class Dog():

def __init__(self, name, breed, age):

self.name = name

self.breed = breed

self.age = age

# If we want the Dog class to know how to perform common dog tasks, we define them next.

def sit(self):

print(self.name.title() + " sits beside you.")

def stay(self):

print(self.name.title() + " stays and does not move when you walk away.")

# Now let's add a dog Oz to the program

my_dog = Dog("Oz","German Shepherd","6")

print("My dog's name is " + my_dog.name.title() + ".")

print("My dog's breed is " + my_dog.breed.title() + ".")

print("My dog's age is " + my_dog.age + ".")

# We do not need the title() function because the age is a number.

# Until we convert the age to an integer, it is a string.

my_dog.sit()

my_dog.stay()

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!