'''lecture_05_hexagon_loops.py Draws a hexagon and n-gon with loops Oliver W. Layton CS 151 Spring 2021 ''' import turtle def hexagon(sideLength): '''Draws a hexagon shape. Parameters: ----------- sideLength: int. length of each edge ''' for i in range(6): turtle.forward(sideLength) turtle.left(60) def ngon(sideLength, nSides): '''Draws an n-sided polygon Parameters: ----------- sideLength: int. length of each side. nSides: int. Total number of sides in the ngon ''' for i in range(nSides): turtle.forward(sideLength) turtle.left(360/nSides) # Main code setup # Speed up drawing turtle.speed(0) # Draw the hexagon with sides 100 pixels long # hexagon(100) # Draw an n-gon ngon(10, 50) # Keep the hexagon up until the user clicks on the window turtle.exitonclick()