Question: - Winning numbers: (13,15,25,3,5,8) Question 1.1. Write a function called simulate_one_ticket. It should take no arguments, and it should return an array with 6 random

 - Winning numbers: (13,15,25,3,5,8) Question 1.1. Write a function called simulate_one_ticket.It should take no arguments, and it should return an array with6 random numbers, simulating how the numbers are selected for a single

- Winning numbers: (13,15,25,3,5,8) Question 1.1. Write a function called simulate_one_ticket. It should take no arguments, and it should return an array with 6 random numbers, simulating how the numbers are selected for a single Lucky Triton Lotto ticket. The first five numbers should all be randomly chosen without replacement, from 1 to 31 . The last number should be between 1 and 8 . [3]: one = np.random. choice ( np.arange (1,32), replace = False ) two = np.random. choice (np. arange (1,32), replace = False ) three = np.random. .hoice ( np. arange (1,32), replace = False ) four =np random, choice (np+ arange (1,32), replace = False ) five =np. random. choice (np.arange (1,32), replace = False ) six=np random. choice (np. arange (1,9)) np.array ( [one, two, three, four, five, six]) [3] : array([13,29,18,5,22,7]) [4]: def simulate_one_ticket(): " "Simulate one Lucky Triton Lotto ticket." " " one = np.random. choice (np.arange (1,32), replace =False) two = np.random. choice (np.arange (1,32), replace = False ) three = np.random. choice (np. arange (1,32), replace = False ) four =np+random, choice (np,arange(1,32), replace = False ) five =np.random. choice (np. arange (1,32), replace = False ) six=nprandom. choice (np arange (1,9)) return np,array ([one, two, three, four, five, six]) [5]: grader.check("q1_1") [5] : q1_1 passed! Question 1.2. It's draw day. You checked the winning numbers King Triton drew, which happened to be (24, 12, 3, 18, 23, 5). You didn't win free housing, and you are quite sad. Suppose you want to remind yourself how unlikely it is to win the grand prize. Call the function simulate_one_ticket 100,000 times. In your 100,000 tickets, how many times did you win the grand prize (free housing)? Assign your answer to count_free_housing . (It would cost a fortune if you were to buy 100,000 tickets - it's pretty nice to be able to simulate this experiment instead of doing it in real life!) Hints: - First, implement a simulation where you only buy 10 tickets. Once you are sure you have that figured out, change it to 100,000 tickets. It may take a little while (up to a minute) for Python to perform the calculations when you are buying 100,000 tickets. - You'll have to count how many of the numbers you chose match the numbers that were drawn. One way to do this involves np. count nonzero. Remember you need all the numbers to match to win the grand prize, and a number is only considered a match if it appears at the same position in your numbers and the winning numbers. everything = np.array ([]) for i in np.arange (100000): one_time = simulate_one_ticket() count_free_housing = np.count_nonzero(one_time ==[24,12,3,18,23,5]) count_free_housing 0 grader.check("q1_2") q1_2 passed! Remember, the mathematical probability of winning free housing is quite low, on the order of 109. That's a lot lower than than 1 in 100,000 , which is 105. Question 1.3. As we've seen, you would need to be extremely lucky to win the grand prize. To encourage more students to buy Lucky Triton Lotto tickets, students can win Triton Cash if some of their numbers match the corresponding winning numbers, as described in the introduction. Again, simulate the act of buying 100,000 tickets, but this time find the greatest number of matches achieved by any of your tickets, and assign this number to most_matches . The winning numbers are the same from the previous part: (24,12,3,18,23,5). For example, if 90,000 of your tickets matched 1 winning number and 10,000 of your tickets matched 2 winning numbers, then you would set most_matches to 2. If 99,999 of your tickets matched 1 winning number and one of your tickets matched 4 winning numbers, you would set most_matches to 4 . If you happened to win the grand prize on one of your tickets, you would set most_matches to 6 . Remember, order matters. Hint: There are several ways to approach this; one way involves storing the number of matches per ticket in an array and finding the largest number in that array. 8]= most_matches = most_matches 8 ] : Ellipsis 9] : one_time = simulate_one_ticket() one_time =np.count_nonzero(one_time ==[24,12,3,18,23,5]) one_time 9]=0 0]: grader.check ("ql_3") 0] : q1_3 results: q1_3 - 1 result

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!