Assignment 20 — function implementation
Due Monday, March 25
Module take_it_away.py
- Your module should implement the below three functions.
- A simple tester taken.py is available.
Function donut( d, h )
- Function parameters
d
andh
are numerics. Returns the volume of a donut whose width isd
and whose hole width ish
. The formula for donut volume is
π2 ( d2 - h2 ) ( d - h ) / 32
The π in the above formula is pi. Remember the best estimate of π in Python is
math.pi
.
- A run of of the tester should produce output
donut( 4.5, 1.75 ): 14.577906891257474:
donut( 3.75, 2.15 ): 4.658453277314178
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'