Question

In: Computer Science

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)

  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

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.

Solutions

Expert Solution

'''

Python version : 2.7

Python program to create and implement a Dice class

'''

from random import randint

#class Dice

class Dice():

               # constructor

               def __init__(self,dice_sides = 6):

                              self.num_sides = dice_sides

              

               # roll function

               def roll(self):

                              return randint(1,self.num_sides)

# create an object of Dice class                 

dice = Dice()

result = [] # list to store the result of rolling a die

# loop to roll a die 100 times and append it to result list

for i in range(100):

               result.append(dice.roll())

# print the result

print(result)        

#end of program

Code Screenshot:

Output:


Related Solutions

Fibonacci Write pseudocode to calculate F(n) Write pseudocode to construct a vector of the first n...
Fibonacci Write pseudocode to calculate F(n) Write pseudocode to construct a vector of the first n numbers in the Fibonacci sequence. Write a function: fibo(n = 1){ # Your code here } which takes one parameter ​n​ and returns the ​nth​ fibonacci number. Use the function you wrote to calculate the 58th Fibonacci number. Include your R code in your report The Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) is defined as F(1) =...
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)
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
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).
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
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...
Write the pseudocode that prompts the user for their first and last name. Display the first...
Write the pseudocode that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user. Ask the user to input a phone number. The program checks which part of Colorado a phone number is from using the values below. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none...
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
PYTHON: Write a script that imports the functions in the module below and uses all of...
PYTHON: Write a script that imports the functions in the module below and uses all of the functions. import math def _main():     print("#" * 28, "\n", "Testing...1, 2, 3...testing!\n", "#" * 28, "\n", sep="")     f = -200     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     f = 125     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     c = 0     print("{:.2f} C is {:.2f} F".format(c, c2f(c)))     c = -200     print("{:.2f} C is {:.2f} F".format(c, c2f(c))) def f2c(temp):     #Converts Fahrenheit tempature to Celcius     if temp <...
Write a comprehensive note on the process of transcription? Write a short note on how mature...
Write a comprehensive note on the process of transcription? Write a short note on how mature mRNA is produced in eukaryotes? What are the roles of loading buffer/loading dye, DNA marker and an ethidium bromide in a gel electrophoresis? During DNA isolation, how the DNA purification can be achieved and why the DNA purity is important in Agricultural biotechnology? What is the role of different restriction endonucleases in agricultural biotechnology? Write a note on the importance of molecular markers in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT