Due by class time Wednesday, March 8
If you wish, you may work with a partner on this assignment.
Finish reading Chapters 7 and 8 of your Python textbook.
Study the code examples from class from this week and last week.
These problems are recommended if you feel the need for some extra programming practice using decisions and loops in Python, but they are not required.
Question 2 on page 227. Trace through the code fragment by hand for each of the given inputs, and then verify your answers by running the code in Python.
Exercise 6 on page 229.
Exercise 7 on page 229.
Exercise 8 on page 229.
Write a program to simulate repeatedly rolling two dice until both come up with the same number. In addition to printing out the dice values, if the program rolls double ones it should print out "Snake eyes!" If double sixes are rolled, it should print out "Box cars!" Otherwise, it should just print out "Doubles!" For example, a sample run of the program might look like the following:
We will simulate rolling two dice until we get doubles... 5 3 1 4 2 6 1 1 Snake eyes!
To generate the dice rolls, you can use random.randrange(a, b) from the random module.
Finish the exercises from Lab 6. Name your programs as follows:
Parts 1-4: piglatin, firstVowelPos, translateWord, translate
Part 5: bmi
Part 6 (Exercise 17 on page 230): bounce
Part 7: rps
Now modify your Rock-Paper-Scissors program so that, unknown to the user, the computer occasionally cheats by changing its own choice after the user has entered theirs. This should happen with a probability of 30%.
Write a program called craps that simulates the casino game of Craps, which is played as follows. You start by rolling two dice and looking at the total. The game then breaks down into the following cases based on that first roll:
You should finish the other problems first before attempting these.
Extend your craps program so that it simulates multiple games, keeping track of the number of games won, and then reports the estimated probability of winning. For example, if the player wins 249 out of 500 games, then the estimated probability of winning is 249/500 = 0.498.
Do Exercise 2 on page 262. Call your program windchill.
Do Exercises 12-14 on pages 293-294. Call your program randomwalk.
Put all of your code into a single file called assign5.py. Include your name at the top of the file as a comment, and submit it using /common/cs/submit/cs30-submit. Be sure to run this command from the directory containing your file.
If you have questions about anything, don't hesitate to ask!