Question: Write a function roll_dice() that takes two arguments in this order: the number of rolls and the number of sides. This function should return

Write a function roll_dice() that takes two arguments in this order: the number of rolls and the number of Let's make a histogram. Write a function text_histogram () that accepts a one argument, a dict with integer

Write a function roll_dice() that takes two arguments in this order: the number of rolls and the number of sides. This function should return a dict with the keys being the possible values for the die, and the values being the number of times that value came up, e.g. for 10 sides and 50 rolls, I might get { 1: 5, 2: 7, 10: 4, } Ensure that all possible die rolls have a corresponding key even if there were zero rolls recorded. Let's make a histogram. Write a function text_histogram () that accepts a one argument, a dict with integer values, and returns a string. For each key-value pair in the input dict, the output string should have a line containing the key, a colon character':', and a number of hashmarks corresponding to the key's associated value. These lines must be in numeric/lexicographic order by their key. Once you have that working, make sure the start of the hashmarks is consistent for each line. Make sure this function works with the roll_dice() function from the previous exercise, and that the label justification works for dice with >10 sides. Example: In [ ]: Out[ ]: histogram = text_histogram({'apple': 2, 'cat': 3, "banana': 2}) print (histogram) apple : ## banana: ## cat Hint: You can cast In [ ]: Out [ ]: : ### variable to a string with str(), e.g. num = 42 str (42) '42'

Step by Step Solution

3.58 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution Heres a Python function rolldice that simulates rolling a die and returns a histogr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!