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

This preview shows page 7 - 12 out of 26 pages.

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 [128]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed Out[128]: 'cfbwqdejsak' _ = ok.grade( 'q2_2' ) def simulate_several_key_strikes (num_strikes): key_strikes_array = make_array() for i in np.arange ( 0 ,num_strikes ) : key_strikes_array = np.append(key_strikes_array,simulate_key_strike()) return "" .join(key_strikes_array) # An example call to your function: simulate_several_key_strikes( 11 )
In [193]: 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 . In [129]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed _ = ok.grade( 'q2_3' ) 0 : 1
Out[129]: 0.0
In [97]: 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 [101]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed _ = ok.grade( 'q2_4' )
Out[101]: 0.35041906843673165
In [102]: Question 7. Do you think that a computer simulation is more or less e ff ective 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.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed _ = ok.grade( 'q2_6' )
3. Sampling Basketball Players This exercise uses salary data and game statistics for basketball players from the 2014-2015 NBA season. The data was collected from Basketball-Reference () and Spotrac () . Run the next cell to load the two datasets.
In [74]: Question 1. We would like to relate players' game statistics to their salaries. Compute a table called full_data that includes one row for each player who is listed in both player_data and salary_data .

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture