logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

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

expert
Jane SimaEducation
(5/5)

883 Answers

Hire Me
expert
Cristopher WebbTechnical writing
(5/5)

679 Answers

Hire Me
expert
Brayden JamesComputer science
(5/5)

752 Answers

Hire Me
expert
Antenaina SandyMarketing
(5/5)

953 Answers

Hire Me
Python Programming

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

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme