Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active July 19, 2021 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minte9/7ef8dcd24e7654ee5cf8c4240e35a74a to your computer and use it in GitHub Desktop.
Save minte9/7ef8dcd24e7654ee5cf8c4240e35a74a to your computer and use it in GitHub Desktop.
"""
Make a copy of square() and change the name to polygon()
Add another parameter named n and modify the body ...
so it draws an n-sided regular polygon.
Hint: The exterior angles of an n-sided regular polygon are 360/n degrees.
import turtle
def square(t, length):
for i in range(4):
t.fd(length)
t.lt(90)
bob = turtle.Turtle()
square(bob, 100)
turtle.mainloop() """
# SOLUTION
import turtle
def poligon(t, length, n):
for i in range(n):
t.fd(length)
t.lt(360/n)
bob = turtle.Turtle()
poligon(bob, 20, 10)
turtle.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment