Class 27 — Friday March 27
Tasty problem solving
To be, not to be — That is the question we ask – The answer, to be
Look both ways
Agenda
- Being functional
Buddying
Problem set — Homework 24
- Module
beanery.py
defines three functionsvolume()
,count()
, andguess()
related to jelly beans.
- The actual module file beanery.py will be available at the start of class.
- None of your functions should get input or print output.
- Tester program yum.py performs some basic testing of
beanery.py
.
To do
- Preview next class activities.
- Try CodingBat – it’s batting practice for writing functions.
- Take another look at function epistle.
- Take another look at today's lesson.
- Preview next class activities activities
- Take another look at the Hands on Python Tutorial.
Set up
- Extra credit awarded for buddying with someone
- The only apps to be running on your laptops are a browser and PyCharm. The browser usage should be limited to CS 1112 materials.
- You must use my beanery.py for this assignment.
- Do not access any past or outside code while working on this assignment.
- Review problem set description.
- Close all other program and module tabs.
Module beanery.py
-
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
math
module constant to 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
- Questions
- What built-in function converts a decimal to an integer?
- Should function
volume()
be helpful?
-
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
- Questions
- Should function
volume()
be helpful?
- Should function
count()
be helpful?
© 2020 Jim Cohoon | Resources from previous semesters are available. |