Class 28 — Wednesday March 27
Tasty problem solving
Winning strategy — Mindful collaboration — Doing it today
Look both ways
Agenda
- Being functional
- Working with others
You got to see it, to believe it
Example de jeur — module beanery
- Module beanery defines three functions
volume()
,count()
, andguess()
.
- A simple tester yum.py is provided.
Function volume( a, b )
- Returns the volume of jelly bean with length
a
and heightb
. Based upon hours of research, zillions of jelly beans, and a bunch of mason jars, it has been concluded that the volume of a jelly bean can be roughly modeled as the average of the volume of the exterior bounding cylinder and of the volume of the interior bounding ellipsoid. Our formula for the volumes
of a single jelly bean is:
To make your calculation as accurate as possible, use Python's estimate of π when needed.
- A run of of the tester should produce output
volume( 1.3 , 0.7 ): 0.41691552507014545
volume( 2.0 , 1.0 ): 1.3089969389957472
Function count( s, j, f )
- Returns the number of beans of volume
s
that can fit a jar with volumej
given the loading capacity isf
.
- The count formula for the volume j of a single jelly bean is:
⌊
j f / s
⌋ ;
where the ⌊ ⌋ operators are the mathematical symbols for rounding down to the nearest integer.
- A run of of the tester should produce output
count( 0.42 , 125 , 0.7 ): 208
count( 1.31 , 500 , 0.6 ): 229
Function guess( a, b, j )
- Returns the number of number jelly beans with length
a
and heightb
that can fit in a jar with volumej
. Exhaustive research has determined the jelly bear jar loading factor is typically 69.8% (i.e., .698).
- A run of of the tester should produce output
guess( 1.3 , 0.7 , 125 ): 209
guess( 2.0 , 1.0 , 500 ): 266
guess( 1.52 , 0.9 , 1550 ): 1342
To do
- Review recent epistles and slide decks