## Class 41 April 27

## I know that

### Always look both ways

### Agenda

- Be chresthomagical

### Test accommodations

- Students with registered conflicts have been sent email on when and where to take the make up.

- SDAC students please report to the Rice 536 at 4:00 PM or 5:30 PM depending upon your accommodation

### Module leap_year.py

- Defines three functions
`leap_year()`

,`months()`

, and`ytd()`

.

`leap_year( y )`

- Returns
`True`

or`False`

depending whether`y`

is a leap year. A year is a leap year, if it is evenly divisible by 4 and not evenly divisible by 100. Also, a year is a leap year, if it is evenly divisible by 400. All other years are not leap years.

`months( y )`

- Returns a 12-element list giving the numbers of days in each month for year
`y.`

`ytd( m, d, y )`

- Returns the day of the year, where the year is
`y`

, the month is`m`

, and the day of the month is`d`

. For example, 1/1/2017 is the 1st day of the year, 12/7/2017 is the 341st of the year, and 3/1/20

### Module dictionary.py

- Defines two functions
`make()`

and`onto()`

.

`make( k, v )`

- If the lengths of
`k`

and`v`

are not equal, the function returns`None`

. Otherwise, the function returns a new`dict`

. In this dictionary, thei^{th}element of`k`

maps to thei^{th}element of`v`

.

`onto( d )`

- Returns
`True`

or`False`

depending whether there are no duplicates in`d`

.

### Module shifty.py

- Defines three functions
`legal()`

,`offset()`

, and`shifttd()`

.

`legal( v )`

- Returns an integer based on integer
`v`

. If`v`

is negative, the function returns 0. If instead`v`

exceeds 255, the function returns 255. Otherwise, the function returns`v`

. Thus, the return value is always a legal value for an individual RGB level.

`offset( pixel, x, y, z )`

- Returns the new color
`( legal( nr ), legal( ng ), legal( nb ) )`

, where`nr`

,`ng`

, and`nb`

are the values gotten by legally decrementing the RGB values of pixel respectively by the amounts`x`

,`y`

, and`z`

.

`shift( original, x, y, z )`

- Returns a new image that is based on original, where a pixel in the new image is obtained by using
`offset()`

on the corresponding pixel in`original`

with offset amounts`x`

,`y`

, and`z`

.

### Module marbles.py

- Defines four functions
`over()`

,`computer()`

,`legal()`

, and`player()`

that together implement a version of the game marbles. This two-person game starts off with*n*marbles being available. The players alternate turns. On a turn, a player must remove at least one marble, but no more than half of the remaining marbles. The player who removes the last marble loses. Our version of the game will have the*computer*play against a person.

`over( n )`

- Returns
`True`

if`n`

equals 1; otherwise, returns`False`

.

`computer( n )`

- Returns the number of marbles the computer takes for its move. The amount is randomly chosen from the inclusive range 1 through
`n / / 2`

.

`legal( n, m )`

- If
`m`

is a legal amount to take, the function returns`True`

; otherwise, the function returns`False`

.

`player( n, m )`

- If
`m`

is a legal amount to take, the function returns`m`

; otherwise, the function returns 0.

- A tester marbles-tester.py is available.