Assignment 21 — function implementation
Due in class, Friday October 25
Module triple.py
- Your module should implement the below three functions.
- A simple tester threat.py is available.
Function inverse( n )
- Parameter
n
is numeric.
- Returns the additive inverse of
n
. The additive inverse ofn
is-n
.
- The function does not produce output or request input.
- A run of of the tester should produce output
inverse( 4.5 ): -4.5
inverse( -12 ): 12
inverse( 0 ): 0
Function longer( s, t
)`
- Function parameters
s
andt
are strings.
- The function returns the longer of
s
andt
. Ifs
andt
have the same length, thens
is returned.
- The function does not produce output or request input.
- A run of of the tester should produce output
longer( abcd, ef ): abcd
longer( hij, klmnnop ): klmnop
longer( str, int ): str
longer( int, str ): int
Function summation( n )
- Function parameter
n
is an integer value.
- The function prints the sum of the integers.
0 + 1 + ... + n
.
- The function does not produce output or request input.
- A run of of the tester should produce output
summation( 5 ): 15
summation( 1 ) : 1
summation( 0 ): 0
© 2019 Jim Cohoon | Resources from previous semesters are available. |