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.
- There should be only one submission per group
Testing
- A simple tester seven.py is available
Function road_trip( d, h )
- Adapted from test 1
- Returns the decimal average speed of a trip of
d
miles overh
hours
- Partial output from a sample run of
seven.py
Average speed for a road trip of 325 miles in 5 hours is 65.0
Average speed for a road trip of 114 miles in 4 hours is 28.5
Function manhattan_distance( a1, s1, a2, s2 )
- Adapted from Homework 9
- 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 17.
- 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 middle( s )
- Function related to function
mid()
of homework 20.
- Partial output from a sample run of
seven.py
- Returns the middle third of string
s
. If the length ofs
is not evenly divisible by 3, then length of the first third (and possibly the middle third) is greater than that of the last third.
Middle third of abcdef is cd
Middle third of abcde is cd
Middle third of abcd is c