Intro to
Programming
(with Python)

Fall 2016
course
navigation

Thu Oct 13

Late Thursday Update:
The network was out during class today.
I discussed the collatz problem from projecteuler , and we wrote in class the code which I have attached.
We barely started talking about the craps simulation.

old business

Let's talk about midterm projects - many of you didn't submit an idea yet.
Last time we had started problem 4 - largest palindrome - from projecteuler.net .
One more ?

new business

Chapter 9 : "simulation and design"
Discusses "top-down", "bottom-up", and "spiral" (which is a bit of both) program design techniques.
The text does this with a racquetball simulation.
I'd like to do something similar as a class exercise, but with a problem that I like a bit better: craps.
As the book describes, we'll use a random number function to implement the dice : def d6(): """Return a random integer from 1 to 6 inclusive.""" from random import randrange return randrange(1,7)
(Before going on, test this manually.)
The program I have in mind looks like this when it runs :
$ python craps.py --- Estimated odds of winning at craps --- How many games would you like to simulate? 100 Simulating 100 games ... done. Number of simulated wins: 38 Estimated odds of winning: 0.381 --- Estimated error --- How many times would you like to repeat that series of 100 games? 10 Simulating 10 sets of 100 games ... done. Lowest estimated odds : 0.363 Highest estimated odds: 0.387 Error range = (high-low) = 0.024
And what I'd like us to investigate are several things, besides just the programming itself:
The rules of craps are described here: http://en.wikipedia.org/wiki/Craps :
(We won't worry about how the betting works.)
We'll see how far we get with working through this together in class.

No class next Tuesday ... so I'll see you in a week. :)
http://cs.marlboro.edu/ courses/ fall2016/python/ notes/ Oct_13
last modified Thursday October 13 2016 4:55 pm EDT

attachments [paper clip]

     name last modified size
   collatz.py Oct 13 2016 4:55 pm 1.37kB    collatz3.py Oct 13 2016 4:55 pm 1.42kB