Please include the following with your assignment submission:
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):
main
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
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.
>>> 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.
>>> 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}
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
>>> 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 == “***”)
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:
The output will be same as print_results.
Submit the file holding all of the function definitions using the assignment 9 dropbox on the D2L site. Submit the following:
The assignment is worth 100 points: dice_role : 20 points
run_test : 30
print_results : 30
dice_probability : 20
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
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. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
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
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