Assignment 21 – function implementation
Due Monday, March 26 — class will be devoted to this effort
Module magnificent.py (file will be available at the start of class)
- Your module should implement the below seven functions. These functions are all related to previous tasks this semester.
- None of your functions should get input or print output.
- Examine and think about algorithms for the problems. However, do not write any code before class.
Testing
- A simple tester seven.py is available
Function beans( a, b, v )
- Adapted from Homework 9.
- Returns an estimate of number of beans in a jar of volume
v
, where the beans are on averagea
in length andb
in height using the value of formulav F / j
, whereF
is the percentage of usable volume in the jar andj
is the size of a jelly bean.
- On average, only 69.8% of the volume of jelly bean jar is usable.
- The volume of a jelly bean is approximately
5 π a b2 / 24
, wherea
andb
are respectively the length and height of the bean.
- Partial output from a sample run of
seven.py
433 beans with length 1.52 and height 0.9 fits in a jar with volume 500
13 beans with length 2 and height 1 fits in a jar with volume 25
Function manhattan_distance( a1, s1, a2, s2 )
- Adapted from Homework 8
- Returns the approximate distance in miles between a person at the corner avenue
a1
and streets1
in Manhattan and a person at the corner of avenuea2
and streets2
in Manhattan.
- NYC distance rules:
- Distance of a Manhattan city block running from one street to the next is on average 1/20th of a mile.
- Distance of a Manhattan city block running from one avenue to the next is on average 3/20th of a mile.
- Partial output from a sample run of
seven.py
Corners ( 6 , 59 ) and ( 7 , 34 ) are 1.4 miles apart
Corners ( 2 , 47 ) and ( 6 , 238 ) are 10.15 miles apart
Function relate( x, y )
- Adapted from Homework 16.
- Returns
'comes before'
,'is equal to'
, or'comes after'
, depending whether the relationships between stringsx
andy
are respectively:
x
alphabetically comes beforey
,
x
is equal toy
, or
x
alphabetically comes aftery
.
- Partial output from a sample run of
seven.py
kiwi is equal to kiwi
apple comes before banana
orange comes after melon
Function youngest( y )
- Adapted from Homework 6
- Returns the youngest acceptable age for a
y
-year old to date according to the dating folk rule you should only date someone who is at least seven years older than than half your age.
- Partial output from a sample run of
seven.py
19 year old can date a 16 year old
22 year old can date a 18 year old
Function is_dateable( y1, y2 )
- Adapted from Homework 6
- Returns
True
orFalse
whether ay2
-year old is an acceptably-aged date for ay1
-year old.
- Your implementation should make use of function
youngest()
.
- Partial output from a sample run of
seven.py
15 year-old can date a 22 year-old is True
22 year-old can date a 15 year-old is False
19 year-old can date a 18 year-old is True
Function mutually_dateable( y1, y2 )
- Adapted from Homework 6
- Returns
True
orFalse
whether both ay2
-year old is an acceptably-aged date for ay1
-year old, and ay1
-year old is an accepta bly-aged date for ay2
-year old
- Your implementation should make use of function
is_dateable()
.
- Partial output from a sample run of
seven.py
25 year-old can date a 65 year-old and vice-versa is False
20 year-old can date a 18 year-old and vice-versa is True
Function check_out( dataset, v )
.
- Adapted from Homework 14
- Parameter
dataset
is a list of rows, where each row is a list of cells (i.e., values). All cell values have the same type.
- Parameter
v
is a value is of the same type as the cells indataset
.
- Returns a list of counts; where the rth count is number of occurrences of v in the rth row of
dataset
.
- Partial output from a sample run of
seven.py
www.cs1112.org/datasets/csv/co1.csv distribution of 6: [1, 0, 2, 0]
www.cs1112.org/datasets/csv/co2.csv distribution of 4: [1, 0, 1, 2, 1, 0]
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!