Assignment 22 – function implementation
Due Tuesday, October 29
Task
- Implement module hodge.py
- Use program podge.py to perform some simple (but not exhaustive) testing of the module.
Module hodge.py
-
Function
sample( d )
- The function has a single decimal parameter
d
, which is a carbon-12 to carbon-14 decay ratio. The function returns an integer estimate of the age of a fossil with a such a ratio. The carbon-14 decay formula for estimating age is:
-8268.3982 * log(
d
)
Because the age is an estimate, it is always truncated to integer. I suspect the built-in
int()
and themath.log()
functions should prove useful.
- The correct output of
podge
testing for the function is below.
sample( 0.35 ) = 8680
sample( 0.005 ) = 43808
sample( 1.0 ) = 0
-
Function
has_vowel( w )
- The function has a single string parameter w. The function returns the logical value
True
, ifw
contains a lowercase vowel; that is, it has at least one occurence of'a'
,'e'
,'i'
,'o'
, or'u'
. If instead,w
does not contain a lowercase vowel, the function returns the logical valueFalse
.
- The correct output of
podge
testing for the function is below.
has_vowel( oxen ) = True
has_vowel( urchin ) = True
has_vowel( mink ) = True
has_vowel( rabbit ) = True
has_vowel( lynx ) = False
© 2019 Jim Cohoon | Resources from previous semesters are available. |