computer science
Optional HW - worth 10 points (1/4 of regular HW)
Due date: October 31
You shouldn’t do this homework unless you’re finished with all others; these are more challenging problems for extra credit. For a Google Colab starter file, go to https://colab. research.google.com/drive/15FN3afmamTD1TI573EZs-12Knp-5kK4s. Do all questions in the same notebook (but use different cells), so that you only need to share and enable one link in your submission.
1. Alice and Bob are playing a game with two standard six-sided dice. They take turns rolling. Whoever rolls a 7 first wins the game. Repeat this game 10,000 times to determine what Alice’s and Bob’s respective chances of winning the game.
2. In basketball, there are two teams, Shooters and Dunkers. Shooters are really good at 3-pointers and take half of their shots as 3-pointers, the other half as 2-pointers. Dunkers always go for 2-pointers. Assume there are no other shots (i.e. no free throws for 1 point, no technical fouls, etc.). Here are the statistics on how they do:
– Shooters make their 3-pointers 35% of the time and their 2-pointers 40% of the time.
– Dunkers make their 2-pointers 50% of the time.
(a) Simulate 40 possessions for each team to get a full game.
(b) Repeat for 10,000 games to determine which team tends to win more often.
(c) Assuming that Shooters can adjust the percentage of times they take 3-pointers (but not their ability to make 2-pointers or 3-pointers), what’s a good strategy for them to take?
3. Two teams, Dominguez High School and Hills High School, are playing basketball. Dominguez is a little better and tends to win about 55% (in a variable called D win perc) of their games. However, they’re playing a series of 7 games, so anything can happen!
Simulate the series of games between the two schools, showing a list of who won each game (D or H), as well as a message displaying the final winner. If the series finishes in less than 7 games, then they don’t play everything.
Hint: recall that the random.randint function can simulate random integers. You can use random.randint(1, 100) to simulate a random number from 1 through 100, and assign 1 through 55 as D wins, and 56 through 100 as H wins.
1
For example, you could end up simulating [’D’,’H’,’D’,’D’,’H’,’D’], showing D wins in games 1, 3, 4, 6, and H wins in games 2, 5. Then display a final message like “Dominguez High wins!”
2