Class 31 — November 9
Functional chresthomathics
The Seven Society: You have had impact — Engaging many bright minds — Keep fueling passion
JPC: I give my thanks to — The Seven Society — You made heart swell so
Look both ways
Agenda
- Consider and do module development
- Prepare for Test 2
Want to be a TA next semester
- Fill out for the application
Problem at hand
- Design a module translate.py to support text translation. (updated, also see artifacts)
- A simple corner tester corner_testing.py for module translate.py (updated)
- Some sample translation text phrases
links
est la baguette fraiche
dubailte dubailte kesusahan und guaio
umlilo adolebitque und ketel bombolla
umucu di una pantanoso neidr
dans der ketel bouyi und cuire
oog di tritons und kaki di rano
yun di fledermoyz und lingua di chien
viperae foarke und blyn cuc stik
moo fotur und ovlet tis
pre eng viehatys di voimakas guaio
mag un inferno salda bouyi und bombolla
To do
- Examine parameter passing nuances for next class
- Review homework solutions to prepare for the test
Task at the other hand
- Six modules are to be defined.
- Each module defines one function.
- Each module also has a built-in tester.
- For this assignment, no late homework is being accepted. Please make sure you submit on time.
Module luna.py
- Defines a function
h()
. The function has a single numeric parameterx
. The function returns the number of hours it takes to get the moon while traveling at a speed ofx
miles per hour. For your information:
elapsed time = distance / speed
- For your convenience the module defines the constant
DISTANCE_IN_MILES_TO_MOON = 238900.0
- Observation: the function makes a straight-forward calculation and returns the result.
- The output of its built-in testing should be
h( 119.45 ) = 2000.0
h( 597.25 ) = 400.0
Module calc.py
- Defines a function
e()
. The function has three parametersx
,y
, ands
. Parametersx
andy
are decimals; parameters
is a string. Ifs
is either'+'
,'-'
,'*'
, or'/
', the function returns respectivelyx + y
,x - y
,x * y
, orx / y
. Otherwise, the functionsNone
.
- Observation: an
if-elif-...else
structure is needed to determine which of five possibile cases applies based on parameters
. Knowing which case applies, allows a straight-forward calculation and then the immediate return of the calculation
- The output of its built-in testing should be
19.5 + 5.25 = 24.75
12.5 - 6.5 = 6.0
12.5 * 4.5 = 56.25
10.0 / 2.25 = 4.444444444444445
1.0 @ 5.0 = None
Module eval.py
- Defines a functions
f()
. The function has two list parametersx
andy
. The function returns a new list whose elements are the elements ofx
followed by the elements ofy
. The function does not change its list parameters.
- Observation: an accumulator is needed. The elements of
x
need to be first added to the accumulator followed by the elements ofy
. Afterwards, the accumulator is returned.
- The built-in testing makes use of the following lists.
x1 = [ ]; y1 = [ ]
x2 = [ 3, 1, 4 ]; y2 = [ ]
x3 = [ ]; y3 = [2, 7, 8]
x4 = [ 3, 1, 4 ]; y4 = [1, 5, 1, 9]
- The output of its built-in testing should be
f( x1, y1 ) = [ ]
f( x2, y2 ) = [ 3, 1, 4 ]
f( x3, y3 ) = [ 2, 7, 8 ]
f( x4, y4 ) = [ 3, 1, 4, 1, 5, 1, 9 ]
Module uate.py
- Defines a function
g()
. The function has one list parameterx
. The function returns a new list whose elements are the element values ofx
without duplication. The function does not change its list parameter.
- Observation: an accumulator is needed. The elements of
x
need to be added to the accumulator one-at-a-time if they are not already there. Afterwards, the accumulator is returned.
- The built-in testing makes use of the following lists.
x1 = [ 0, 1, 2 ]
x2 = [ 0, 4, 1, 2, 2, 1, 3, 6, 3, 3, 4 ]
x3 = [ ]
- The output of its built-in testing should be
g( x1 ) = [ 0, 1, 2 ]
g( x2 ) = [ 0, 4, 1, 2, 3, 6 ]
g( x3 ) = [ ]
Module sigma.py
- Defines a function
s()
. The function has one parameterd
. Parameterd
is an already initialized integer dataset; that is, it is a list of integer lists. The function returns the sum of the dataset values. The function does not change its list parameter.
- Observation: an accumulator is needed to store the sum of the dataset values. The sum of the values for each row of the dataset needs to be added to the accumulator. Afterwards, the accumulator is returned.
- The built-in testing makes use of the following lists.
d1 = [ [ 0 ], [ 1, 2 ], [ 1, 2, 3 ], [ 0 ] ]
d2 = [ [ 1, 0, 1, 2, 2 ], [ 3, 0, 1, 1, 1, 0 ], [ 2 ], [ 0, 0, 1 ] ]
d3 = [ [ 3, 0, 3], [ 3, 0, 3, 0, 1], [ 1, 0, 2 ] ]
d4 = [ ]
- The output of its built-in testing should be
s( d1 ) = 9
s( d2 ) = 15
s( d3 ) = 16
s( d4 ) = 0
Module trio.py
- Defines a function
t()
. The function has one list parameterx
of numeric values. The function does not change its list parameter. The function returns a new three-element list whose values are respectively the number of negative, zero, and positive values inx
.
- Observation: three accumulators are needed to store the three wanted counts. Each element of the list needs to be examined to determine which count should be incremented based on its numeric property. Afterwards, the return is a list of three elements (i.e, the computed counts).
- The built-in testing makes use of the following lists.
x1 = [ 0, -3, 0, -4, -2 ]
x2 = [ -3, 1, -2, 1, -3, -3, -2, -4, -1, -4 ]
x3 = [ 2, -1, 0, 3, 0, 3, -2, -2, -1, -4, 3, -4, 3, -1, 3 ]
x4 = [ ]
- The output of its built-in testing should be
t( x1 ) = [ 3, 2, 0 ]
t( x2 ) = [ 8, 0, 2 ]
t( x3 ) = [ 7, 2, 6 ]
t( x4 ) = [ 0, 0, 0 ]
Homework solutions to review
- Assignment 16: same_difference.py
- Assignment 17: do_you_relate.py
- Assignment 18: olio.py
- Assignment 19: take_two.py
- Assignment 20: magnificent.py
- Assignment 21: quad.py
- Assignment 22: aid.py
© 2019 Jim Cohoon | Resources from previous semesters are available. |