Last active
July 19, 2021 12:14
-
-
Save minte9/7ef8dcd24e7654ee5cf8c4240e35a74a to your computer and use it in GitHub Desktop.
Python / Language / Poligon - https://www.minte9.com/python/language-loops-1250
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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