logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Add a comment at the top of your file describing for each person, what they contributed to the assignment. This must be at least 2-3 sentences and be very specific and detailed.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

CSC 241 Computer Science

Assignment 9

Logistics

Please include the following with your assignment submission:

  1. A comment at the top of your file identifying any classmates with whom you discussed or in any other way collaborated on the assignment. You may work (directly or indirectly) with no more than three other people
  2. Add a comment at the top of your file describing for each person, what they contributed to the assignment. This must be at least 2-3 sentences and be very specific and detailed.

 

Assignment

Implement the functions below in the file csc241-homework-9.py which can be found on the D2L site in the Week 9 homework section. You should save the template file I provided and then modify that file by adding the bodies for the functions. When you do, make sure to remove the placeholder pass statements that are currently there.

 

You must also write doc strings for every function. A submission without doc strings will not earn full credit.

 

Be careful to avoid disturbing the doctest strings and the test code at the bottom. Remember that when you execute the entire file (press F5 or menu choice Run/Run module), your solutions will be tested. An error free test result looks like this (just shows test summary):

 

1 items had no tests:

     main     

4 items passed all tests:

2

tests

in   main      .dice_probability

6

tests

in   main .dice_role

1

tests

in   main .print_results

2

tests

in   main .run_test

11 tests in 5 items.

11 passed and 0 failed. Test passed

 

Note that the template contains the import statement:

 

from random import randint, seed

 

so randint and seed are available already and do not require “random” in front of them (use randint(1,10) not random.randint(1, 10) ). If you feel you need additional functions from the random module, you need to import them.

 

Exercise 1

def dice_role()

 

Input: no inputs

 

Result: returns a tuple representing 2 dice

 

Details: This function needs simulate a role of the dice by generating 2 random numbers, each between 1 and 6 inclusively. The function returns these 2 numbers a tuple.

 

Examples:

>>> seed(123)

>>> dice_role() (1, 3)

>>> dice_role() (1, 4)

>>> dice_role() (3, 1)

>>> dice_role() (1, 4)

>>> dice_role() (5, 5)

 

 

Exercise 2

def run_test(test_cnt):

 

Input: the number of tests to run

 

Result: returns a dictionary containing the results from test_cnt executions of dice_role().

 

Details: The function executes dice_role() the specified number of times. It keeps track of the results in a dictionary. The keys to the dictionary are the sum of the 2 dice returned from dice_role().  If the result from dice_role() is (4, 3), 7 is put in the dictionary.

 

The values added to the dictionary are the number of times the key was a result from dice_role. Notice for example that these roles: (4,3), (3, 4), (5, 2) will all be recorded in the dictionary as 7.

 

Example output:

>>> seed(123)

>>> run_test(50)

{4: 5, 5: 6, 10: 4, 6: 6, 3: 4, 8: 7, 9: 7, 2: 2, 7: 5, 11:

3, 12: 1}

 

 

Exercise 3

def print_results(results):

 

Inputs: a dictionary containing the results generated by run_test()

 

Results: prints a chart of the results

 

Details: This function is responsible for printing the results produced by run_test. It produces a histogram (a type of bar chart)using ‘*’ to represent 1 unit. If you like to know more about histograms, have a look at this:

 

https://www.spss-tutorials.com/histogram-what-is-it/

 

The function first gets a sorted list of the keys of the dictionary, then prints a bar for each key in the list

 

Example output:

>>> print_results(test_data) 2 **

3 ****

4 *****

5 ******

6 ******

7 *****

8 *******

9 *******

10 ****

11 ***

12 *

 

Hint: Use string multiplication to produce the right number of ‘*’ (‘*” * 3 == “***”)

 

Exercise 4

def dice_probability(test_cnt):

 

Inputs: number of test runs to perform

 

Results: indirectly prints the chart described above

 

Details: This is the main function for this assignment but it will be very short. It needs to do 2 things:

  1. call run_test, giving it the specified number of dice_roles to produce
  2. call print_results, using the results from run_test as its input.

 

The output will be same as print_results.

 

 

Submitting the assignment

Submit the file holding all of the function definitions using the assignment 9 dropbox on the D2L site. Submit the following:

 

  1. Your Python file (csc241-homework-9.py) with all of your function definitions inside of it.
  2. Your shell transcript saved as a .txt file (you must override the default of *.py)

 

Grading

The assignment is worth 100 points: dice_role : 20 points

run_test : 30

print_results : 30

dice_probability : 20

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

979 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

892 Answers

Hire Me
expert
Husnain SaeedComputer science

893 Answers

Hire Me
expert
Atharva PatilComputer science

991 Answers

Hire Me