Checkpoint 5.4.1.
Where in this code should you place function assumptions?
import turtle
def square():
"""Draws a square"""
for _ in range(4):
amy.forward(30)
amy.right(90)
def star():
"""Draws squares in rotation around a point to form a star"""
num_squares = 5
angle = 360/num_squares # turn 72 degrees before drawing each square
for _ in range(num_squares):
amy.right(angle)
square()
wn = turtle.Screen() # Set up the window and its attributes
amy = turtle.Turtle() # create amy
amy.speed(10) # make turtle draw fast
amy.color("red") # draw first flower in red
star()
# move to new location and draw window
amy.penup()
amy.goto(50,50)
amy.pendown()
amy.color("blue")
star()
# move to new location and draw window
amy.penup()
amy.goto(-50,-50)
amy.pendown()
amy.color("orange")
star()
# move to new location and draw window
amy.penup()
amy.goto(50,-50)
amy.pendown()
amy.color("green")
star()
-
Above the function definitions
-
Putting assumptions outside of the function we want to make it for does not make sense.
-
Commented directly below both function docstrings
-
Function assumptions are technically comments, but this chapter shows how they should be implemented.
-
Assumptions are not needed in this code
-
While assumptions and docstrings are technically not needed to run code, They are needed to help you understand what the programmer was trying to achieve.
-
Within the docstrings of both functions
-
Yes, assumptions should be made inside of their functionโs respective docstrings.
-
At the end of the function code
-
While it may be inside the right function this way, it makes more sense if assumptions are placed before the functionโs code.
