Instructions for functionsTest

(produced at 02:11 a.m. on 2021-08-28)

For this task, you will need to write four functions:

  1. indentMessage - A function which adds spaces to indent a string to a certain minimum length.
  2. printMessage - Uses indentMessage to indent a message and also prints it.
  3. ellipseArea - Calculates and returns the area of an ellipse given its radii.
  4. polygon - Uses turtle functions to draw a polygon.

Note: these instructions are not really detailed enough for a real assignment!

Examples

Examples for indentMessage

Some examples of correct results for indentMessage:

In []:
indentMessage('hello', 10)
Out[]:
' hello'
In []:
indentMessage('name', 5)
Out[]:
' name'
In []:
indentMessage('name', 2)
Out[]:
'name'

Examples for printMessage

Some examples of correct printed output for printMessage:

In []:
printMessage('hello', 10)
Prints
hello
In []:
printMessage('name', 5)
Prints
name
In []:
printMessage('name', 2)
Prints
name

Examples for ellipseArea

Some examples of correct results for ellipseArea:

In []:
ellipseArea(1, 1)
Out[]:
3.141592653589793
In []:
ellipseArea(5, 10)
Out[]:
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 []:
polygon(100, 3)
Image In []:
polygon(80, 4)
Image In []:
polygon(60, 8)
Image In []:
polygon(30, 16)
Image

Rubric

 
unknown Style Requirements
How your code is written.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown All functions are documented
Each function you define must include a non-empty documentation string as the very first thing in the function.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown Do not ignore the results of any fruitful function calls
According to the "Don't waste fruit" principle, every place you call a fruitful function (built-in or custom) you must store the result in a variable, or that function call must be part of a larger expression that uses its return value.
 
unknown Do not create any variables that you never make use of
According to the "Don't waste boxes" principle, every time you create a variable (using = 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.
 
unknown Procedure Requirements
What code you use to solve the problem.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown No errors loading code
Your code should be able to be loaded without errors. Run your code before submitting it to make sure this is true.
 
unknown Define indentMessage with 2 arguments
Use def to define indentMessage with 2 arguments
 
unknown Call len
Within the definition of indentMessage with 2 arguments, call len in at least once place.
 
unknown Define printMessage
Use def to define printMessage
 
unknown Call print
Within the definition of printMessage, call print in at least once place.
 
unknown Call indentMessage
Within the definition of printMessage, call indentMessage in at least once place.
 
unknown Define ellipseArea
Use def to define ellipseArea
 
unknown Use a return statement
Within the definition of ellipseArea, use return _ in at least once place.
 
unknown Define polygon
Use def to define polygon
 
unknown Use a loop
Within the definition of polygon, use a for or while loop in at least once place.
 
unknown Call fd
Within the loop within the definition of polygon, call fd or forward in at least once place.
 
unknown Process Requirements
How your code achieves its results.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown polygon makes the correct function calls
Your polygon function must call the fd function with the correct arguments, while the correct position and heading valuesareset up
 
unknown The polygon function must maintain invariants for the position and heading values
Each call to the polygon function must return the position and heading values to their initial state before it returns.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown polygon makes the correct function calls
Your polygon function must call the fd function with the correct arguments, while the correct position and heading valuesareset up
 
unknown The polygon function must maintain invariants for the position and heading values
Each call to the polygon function must return the position and heading values to their initial state before it returns.
 
unknown Product Requirements
Your code's result values.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown indentMessage returns the correct result
The result returned when your indentMessage function is run must match the solution result.
 
unknown ellipseArea returns the correct result
The result returned when your ellipseArea function is run must match the solution result.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown indentMessage returns the correct result
The result returned when your indentMessage function is run must match the solution result.
 
unknown Behavior Requirements
What your code does from the user's perspective.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown printMessage prints the correct output
The output printed when your printMessage function is run must match the solution output.
 
unknown printMessage uses correct indentation
We will verify that printMessage includes the correct number of spaces before the message itself.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown printMessage prints the correct output
The output printed when your printMessage function is run must match the solution output.
 
unknown Testing Requirements
What tests you define for your code and their results.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown Defines tests for each core function
Your code must use the 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 cases
  • printMessage: 2 test cases
  • ellipseArea: 2 test cases
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown All defined expectations were met
Every expectation that your code establishes using the optimism module must be met, and it must establish at least one expectation.
 
unknown Core expectations are correct
Every expectation that your code establishes involving any of the following functions must work when run again using the solution code:
  • indentMessage
  • printMessage
  • ellipseArea