Question 3 write a function called nachoreaction that

This preview shows page 5 - 10 out of 34 pages.

Question 3. Write a function called nacho_reaction that returns a string based on the type of nacho passed in as an argument. From top to bottom, the conditions should correspond to: 'cheese' 'salsa' , 'both' , 'neither' , . Hint: If you're failing the test, double check the spelling of your reactions. Out[9]: 'More please' Out[10]: 'More please' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Running tests -------------------------------------------------------------------- - Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed
2/24/19, 11(55 PM lab05_master Page 6 of 34 In [12]: def nacho_reaction (nacho): if ... : return 'Cheesy!' # next condition should return 'Spicy!' ... # next condition should return 'Wow!' ... # next condition should return 'Meh.' ... spicy_nacho = nacho_reaction( 'salsa' ) spicy_nacho In [13]: def nacho_reaction (nacho): if nacho == 'cheese' : return 'Cheesy!' elif nacho == 'salsa' : return 'Spicy!' elif nacho == 'both' : return 'Wow!' else : return 'Meh.' spicy_nacho = nacho_reaction( 'salsa' ) spicy_nacho In [14]: _ = ok . grade( 'q1_3' ) Out[12]: 'Cheesy!' Out[13]: 'Spicy!' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Running tests -------------------------------------------------------------------- - Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed
2/24/19, 11(55 PM lab05_master Question 4. Create a table ten_nachos_reactions that consists of the nachos in ten_nachos well as the reactions for each of those nachos. Hint: Use the apply method. as )
Page 7 of 34
2/24/19, 11(55 PM lab05_master Page 8 of 34 In [17]: _ = ok . grade( 'q1_4' ) Question 5. Using code, find the number of 'Wow!' reactions for the nachos in ten_nachos_reactions In [18]: number_wow_reactions = np . count_nonzero(ten_nachos_reactions . column( eactions' ) == 'Wow!' ) #SOLUTION number_wow_reactions In [19]: _ = ok . grade( 'q1_5' Question 6. Allie is playing darts. Her dartboard contains ten equal-sized zones with point values from 1 to 10. Write code that simulates her total score after 1000 dart tosses. Hint: First decide the possible values you can take in the experiment (point values in this case). Then use np.random.choice to simulate Allie's tosses. Finally, sum up the scores to get Allie's total score. Out[18]: 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Running tests -------------------------------------------------------------------- - Test summary Passed: 2 Failed: 0 [ooooooooook] 100.0% passed . 'R ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Running tests -------------------------------------------------------------------- - Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed
2/24/19, 11(55 PM lab05_master Page 9 of 34 In [20]: possible_point_values = ...

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture