Hint if you make a list or array of the simulated key

This preview shows page 4 - 7 out of 14 pages.

Out[10]: 2.7245398995795435e-16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Out[12]: 'z' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed
Hint: If you make a list or array of the simulated key strikes, you can convert that to a string by calling "".join(key_strikes_array) (if your array is called key_strikes_array ). In [14]: def simulate_several_key_strikes (num_strikes): # Fill in this function. Our solution used several lines # of code. key_strikes_array = make_array() for i in np . arange(num_strikes): key_strikes_array = np . append(key_strikes_array,simulate_key_strike()) return "" . join(key_strikes_array)
return "" . join(key_strikes_array) # An example call to your function: simulate_several_key_strikes( 11 ) In [15]: _ = ok . grade( 'q2_3' ) Question 4. Use simulate_several_key_strikes 1000 times, each time simulating the monkey striking 11 keys. Compute the proportion of times the monkey types "datascience" , calling that proportion datascience_proportion . This is an estimate for the true probability that a monkey types "datascience" . )) ) Out[14]: 'dxzllojsaff' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed
Question 5. Check the value your simulation computed for datascience_proportion . Is your simulation a good way to estimate the chance that the monkey types "datascience" in 11 strikes (the answer to question 1)? Why or why not?
Question 6. Compute the chance that the monkey types the letter "e" at least once in the 11 strikes. Call it e_chance . Use algebra and type in an arithmetic equation that Python can evalute. In [44]: e_chance = 1- (( 25/26 ) **11 )
e_chance In [45]: _ = ok . grade( 'q2_6' ) Question 7. Do you think that a computer simulation is more or less effective to estimate e_chance compared to when we tried to estimate datascience_chance this way? Why or why not? (You don't need to write a simulation, but it is an interesting exercise.)

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture