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

### Agenda

• Consider and do module development

### Problem at hand

• Some sample translation text phrases

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

• 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 parameter `x`. The function returns the number of hours it takes to get the moon while traveling at a speed of `x` 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 parameters `x`, `y`, and `s`. Parameters `x` and `y` are decimals; parameter `s` is a string. If `s` is either `'+'`, `'-'`, `'*'`, or `'/`', the function returns respectively `x + y`, `x - y`, `x * y`, or `x / y`. Otherwise, the functions `None`.
• Observation: an `if-elif-...else` structure is needed to determine which of five possibile cases applies based on parameter `s`. 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 parameters `x` and `y`. The function returns a new list whose elements are the elements of `x` followed by the elements of `y`. 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 of `y`. 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 parameter `x`. The function returns a new list whose elements are the element values of `x` 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 parameter `d`. Parameter `d` 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 parameter `x` 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 in `x`.
• 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 ]