## 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 average`a`

in length and`b`

in height using the value of formula`v F / j`

, where`F`

is the percentage of usable volume in the jar and`j`

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 b`

, where^{2}/ 24`a`

and`b`

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 street`s1`

in Manhattan and a person at the corner of avenue`a2`

and street`s2`

in Manhattan.

- NYC distance rules:

- Distance of a Manhattan city block running from one street to the next is on average 1/20
^{th}of a mile.

- Distance of a Manhattan city block running from one avenue to the next is on average 3/20
^{th}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 strings`x`

and`y`

are respectively:

`x`

alphabetically comes before`y`

,

`x`

is equal to`y`

, or

`x`

alphabetically comes after`y`

.

- 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`

or`False`

whether a`y2`

-year old is an acceptably-aged date for a`y1`

-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`

or`False`

whether both a`y2`

-year old is an acceptably-aged date for a`y1`

-year old, and a`y1`

-year old is an accepta bly-aged date for a`y2`

-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 in`dataset`

.

- Returns a list of counts; where the
*r*^{th}count is number of occurrences of v in the*r*^{th}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]