For this task, you will need to write four functions:
indentMessage
- A function which
adds spaces to indent a string to a
certain minimum length.printMessage
- Uses indentMessage
to
indent a message and also prints it.ellipseArea
- Calculates and returns
the area of an ellipse given its radii.polygon
- Uses turtle
functions to
draw a polygon.Note: these instructions are not really detailed enough for a real assignment!
Examples for indentMessage
Some examples of correct results for indentMessage
:
In []:Out[]:indentMessage('hello', 10)
In []:' hello'
Out[]:indentMessage('name', 5)
In []:' name'
Out[]:indentMessage('name', 2)
'name'
Examples for printMessage
Some examples of correct printed output for printMessage
:
In []:PrintsprintMessage('hello', 10)
helloIn []:PrintsprintMessage('name', 5)
nameIn []:PrintsprintMessage('name', 2)
name
Examples for ellipseArea
Some examples of correct results for ellipseArea
:
In []:Out[]:ellipseArea(1, 1)
In []:3.141592653589793
Out[]:ellipseArea(5, 10)
157.07963267948966
Note that your results do not have to match every single decimal place, as long as they're within about 0.1% of the correct answer.
Examples for polygon
Some examples of correct drawings for polygon
:
In []:Imagepolygon(100, 3)
In []:
Imagepolygon(80, 4)
In []:
Imagepolygon(60, 8)
In []:
Imagepolygon(30, 16)
=
or by defining a parameter for a function) you must also later use that variable as part of another expression. If you need to create a variable that you won't use, it must have the name _
, but you should only do this if absolutely necessary.indentMessage
with 2 arguments
def
to define indentMessage
with 2 argumentslen
indentMessage
with 2 arguments, call len
in at least once place.printMessage
def
to define printMessage
print
printMessage
, call print
in at least once place.indentMessage
printMessage
, call indentMessage
in at least once place.ellipseArea
def
to define ellipseArea
return
statement
ellipseArea
, use return _
in at least once place.polygon
def
to define polygon
polygon
, use a for
or while
loop in at least once place.fd
polygon
, call fd
or forward
in at least once place.polygon
makes the correct function calls
polygon
function must call the fd
function with the correct arguments, while the correct position and heading valuesareset uppolygon
function must maintain invariants for the position
and heading
values
polygon
function must return the position
and heading
values to their initial state before it returns.polygon
makes the correct function calls
polygon
function must call the fd
function with the correct arguments, while the correct position and heading valuesareset uppolygon
function must maintain invariants for the position
and heading
values
polygon
function must return the position
and heading
values to their initial state before it returns.indentMessage
returns the correct result
indentMessage
function is run must match the solution result.ellipseArea
returns the correct result
ellipseArea
function is run must match the solution result.indentMessage
returns the correct result
indentMessage
function is run must match the solution result.printMessage
prints the correct output
printMessage
function is run must match the solution output.printMessage
uses correct indentation
printMessage
includes the correct number of spaces before the message itself.printMessage
prints the correct output
printMessage
function is run must match the solution output.optimism
module to establish a certain number of test cases for each of the following functions (each test case must be followed by at least one expectation):indentMessage
: 2 test casesprintMessage
: 2 test casesellipseArea
: 2 test casesoptimism
module must be met, and it must establish at least one expectation.indentMessage
printMessage
ellipseArea