Question

In: Computer Science

write the pseudocode to process these tasks: From the random module import randint to roll each...

write the pseudocode to process these tasks:

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

Solutions

Expert Solution

thanks for the question here are the two modules

============================================================

# code for the first module
from random import randint


class Dice():
    def __init__(self, dice_sides=6):
        self.num_sides = 6

    def roll(self):
        return randint(1, self.num_sides)

###########################################################################


# Code for second module
dice = Dice()
results = []

for _ in range(100):
    fv = dice.roll()
    results.append(fv)

print(results)

============================================================


Related Solutions

PYTHON PLEASE-------- For the first module, write the pseudocode to process these tasks: (Note: lines beginning...
PYTHON PLEASE-------- 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...
Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module...
Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module public static void score_search(int s,int score[]) { // Initialise flag as 0 int flag=0; // Looping till the end of the array for(int j=0;j<10;j++) { // If the element is found in the array if(s==score[j]) { // Update flag to 1 flag=1; } } // In case flag is 1 element is found if(flag==1) { System.out.println("golf score found"); } // // In case flag...
write pseudocode for this program . thank you import random class cal():    def __init__(self, a,...
write pseudocode for this program . thank you import random class cal():    def __init__(self, a, b):        self.a = a        self.b = b    def add(self):        return self.a + self.b    def mul(self):        return self.a * self.b    def div(self):        return self.a / self.b    def sub(self):        return self.a - self.b def playQuiz():    print("0. Exit")    print("1. Add")    print("2. Subtraction")    print("3. Multiplication")    print("4. Division")...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import load_iris”. Split the dataset into two sets: 20% of samples for training, and 80% of samples for testing. NOTE 1: Please use “from sklearn.model_selection import train_test_split” with “random_state=N” and “test_size=0.80”. NOTE 2: The offset/bias column is not needed here for augmenting the input features. (b) Generate the target output using one-hot encoding for both the training set and the test set. (c) Using the...
Write a Pearson Module pseudocode that asks the user to enter an object’s mass in kgs,...
Write a Pearson Module pseudocode that asks the user to enter an object’s mass in kgs, and then calculate its weight. If the object weighs more than 1000 Newtons, display a message indicating that is too heavy. Otherwise display a message indicating that the object is light. Test your code in Flowgorithm. Given: Weight = Mass * 9.8 (where mass is in kilograms)
After reading the texts and mini-lectures in this module write a paper that completes the tasks...
After reading the texts and mini-lectures in this module write a paper that completes the tasks below. Read the following excerpts as if these characters were clients that you work with. Write an example of the skills as if you were therapist/counselor. You may copy the excerpts and format (below) and paste into your own Word document to complete and submit. EXCERPT 1 I have no place to turn. I am always alone ..I mean I have a lot of...
Tasks 2 Write algorithms in pseudocode to implement a LinkedList The following operations must be performed...
Tasks 2 Write algorithms in pseudocode to implement a LinkedList The following operations must be performed on the LinkedList: *Add an element *Insert an element at a given position x. *Retrieve/Read the value of an element at position y. *Delete an element from position z. (x,y and z represent any value in the valid range of indices of the LinkedList).
Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT