In class exercises

Biggest Circle

[~]$ cs21/inclass/w06-functions/ [w06-functions]$ vim biggest_circle.pyWe'll start today by practicing writing functions some more. In

Look at the line in main `bigCirc = findBiggest(allcircs)`. Does findBiggest take any input? If so, what is the type of this input? Should findBiggest return a value? If so, what is the type of this return?

Let's write a function *stub* that has the matching inputs and return values for `findBiggest`

Now let's write a working version of `findBiggest`. How do we compare circle sizes? How do we extract this info from one circle object? How do we compare against all circles? How do we remember the biggest circle? How do we know when we are done? How do we know we are correct?

File Demo

Run update21 and change to the inclass/w07-design directory.
[w07-design]$ ls colors.txt fileDemo.py showContents.py [w07-design]$Open

Think about the answers to the following questions. Feel free to modify the program or use the python shell to help you answer these questions.

- What does
`fileDemo.py`do? - What is the format of
`colors.txt`? - What type of data does the
`readlines()`method return? - To which class of data (what type?) does the
`readlines()`belong? - What does the
`strip()`method do? - What does the
`strip()`method return? - Does the
`strip()`method modify the original data? - To which class of data (type) does the
`strip()`method belong?

showContents

Open Using `argv`

Design

The basic idea is to start with the general problem and try to express
a solution in terms of smaller problems. Then each smaller problem is
handled in the same way until eventually the problems get so small
that they are trivial to solve. Then you write each piece, test it,
and join it in the with the solution so far.
Let's demonstrate this idea with the dice game Craps.

A player rolls a pair of six-sided dice.

If the initial roll is 2, 3, or 12, the player loses.

If the initial roll is 7 or 11, the player wins.

Any other initial roll causes the player to "roll for point". This means that the player keeps rolling either until she re-rolls the initial value (a win) or rolls a 7 (a loss).

Let's write a program to simulate multiple games of craps and estimate the probability that the player wins.

Specification

Input: Number of games to simulate

Output: Probability of winning