Assignment 19 — function implementation
Due Sunday, October 28
Module take_two.py
- Your module should implement the below two functions.
- A simple tester taken.py is available.
Function signum( x )
- Function parameter
x
is a numeric value. The function does not print any output. The function returns integer-1
,0
, or1
depending respectively whetherx
is negative, zero, or positive.
- A run of of the tester should produce output
f( -3.5 ): -1
f( 0 ) : 0
f( 5 ): 1
Function mid( s )
- Function parameter
s
is a string. If the length ofs
is odd, the function returns the middle character ofs
; otherwise, the function returns the two middle characters ofs
. The function does not print any output.
- For example,
mid(
'abcdef'
)
evaluates to'cd'
andmid(
'abcde'
)
- A run of of the tester should produce output
mid( 'abcdef' ): 'cd'
mid( 'abcde' ): 'c'
© 2019 Jim Cohoon | Resources from previous semesters are available. |