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()
, andytd()
.
leap_year( y )
- Returns
True
orFalse
depending whethery
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 ism
, and the day of the month isd
. 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()
andonto()
.
make( k, v )
- If the lengths of
k
andv
are not equal, the function returnsNone
. Otherwise, the function returns a newdict
. In this dictionary, the i th element ofk
maps to the i th element ofv
.
onto( d )
- Returns
True
orFalse
depending whether there are no duplicates ind
.
Module shifty.py
- Defines three functions
legal()
,offset()
, andshifttd()
.
legal( v )
- Returns an integer based on integer
v
. Ifv
is negative, the function returns 0. If insteadv
exceeds 255, the function returns 255. Otherwise, the function returnsv
. 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 ) )
, wherenr
,ng
, andnb
are the values gotten by legally decrementing the RGB values of pixel respectively by the amountsx
,y
, andz
.
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 inoriginal
with offset amountsx
,y
, andz
.
Module marbles.py
- Defines four functions
over()
,computer()
,legal()
, andplayer()
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
ifn
equals 1; otherwise, returnsFalse
.
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 returnsTrue
; otherwise, the function returnsFalse
.
player( n, m )
- If
m
is a legal amount to take, the function returnsm
; otherwise, the function returns 0.
- A tester marbles-tester.py is available.
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!