Question 1 you roll a 6 sided die 10 times what is

This preview shows page 2 - 6 out of 40 pages.

Question 1. You roll a 6-sided die 10 times. What is the chance of getting 10 sixes?
Question 2. Take the same problem set-up as before, rolling a fair dice 10 times. What is the chance that every roll is less than or equal to 5?
2
In [52]: five_or_less = 3 five_or_less Out[52]: 3 In [53]: _ = ok . grade( ' q1_2 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Question 3. Assume we are picking a lottery ticket. We must choose three distinct numbers from 1 to 100 and write them on a ticket. Next, someone picks three numbers one by one, each time without putting the previous number back in. We win if our numbers are all called. If we decide to play the game and pick our numbers as 12, 14, and 89, what is the chance that we win? Our proposed answer: ( 3 100 ) 3 Assign lottery to either 1, 2, or 3. In [54]: lottery = 3 In [55]: _ = ok . grade( ' q1_3 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Question 4. Assume we have two lists, list A and list B. List A contains the numbers [10,20,30], while list B contains the numbers [10,20,30,40]. We choose one number from list A randomly and one number from list B randomly. What is the chance that the number we drew from list A is larger than the number we drew from list B?
3
In [56]: list_chances = 2 In [57]: _ = ok . grade( ' q1_4 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed 1.2 2. Monkeys Typing Shakespeare (...or at least the string "datascience") A monkey is banging repeatedly on the keys of a typewriter. Each time, the monkey is equally likely to hit any of the 26 lowercase letters of the English alphabet, regardless of what it has hit before. There are no other keys on the keyboard. Question 1. Suppose the monkey hits the keyboard 11 times. Compute the chance that the monkey types the sequence datascience . (Call this datascience_chance .) Use algebra and type in an arithmetic equation that Python can evalute. In [11]: datascience_chance = pow ( 1/26 , 11 ) datascience_chance Out[11]: 2.7245398995795435e-16 In [12]: _ = ok . grade( ' q2_1 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Question 2. Write a function called simulate_key_strike . It should take no arguments , and it should return a random one-character string that is equally likely to be any of the 26 lower-case English letters. In [13]: # We have provided the code below to compute a list called letters, # containing all the lower-case English letters. Print it if you # want to verify what it contains. 4
import string letters = list (string . ascii_lowercase) def simulate_key_strike (): """Simulates one random key strike.""" return np . random . choice(letters) # An example call to your function: simulate_key_strike() Out[13]: ' r ' In [14]: _ = ok . grade( ' q2_2 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Question 3.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture