Assignment 21 – function implementation
Due Wednesday, March 27
Module hodge.py
- The module defines two functions from the CS 1112 past.
- Program podge.py provides some simple testing of the functions.
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. For your information, the math.log() function 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 one 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