In: Computer Science
Part One: Write a program to draw a repetitive pattern or outline of a shape using for loops and Turtle Graphics. Use the following guidelines to write your program.
Insert your pseudocode here:
Part Two: Code the program. Use the following guidelines to code your program.
import turtle
# Creates a Turtle
draw = turtle.Turtle()
# Defines a function to draw a square
def squarePattern():
# Sets the background color
turtle.bgcolor("light green")
# Sets the pen color to red
draw.color("red")
# Loops 4 times
for times in range(4):
# Moves the pen forward
draw.forward(50)
# Turn the pen right side
draw.right(90)
turtle.done()
def starPattern():
# Sets the background color
turtle.bgcolor("blue")
# Sets the pen color white
draw.color("white")
# Loops 5 times
for times in range(5):
# Moves the pen forward
draw.forward(50)
# Moves the pen right
draw.right(144)
turtle.done()
def polygonPattern():
# Sets the background color
turtle.bgcolor("yellow")
# Accepts number of sides of polygon
sides = int(input("Enter number of sides: "))
# Calculates the angle
angle = 360.0 / sides
# Loops number of side times
for times in range(sides):
# Moves the pen forward
draw.forward(80)
# Moves the pen right
draw.right(angle)
turtle.done()
# Displays menu
print("************* MENU ************* ")
print("S - Star")
print("P - Polygon")
print("Q - Square")
# Accepts user choice
ch = input("Enter your choice: ")
# Checks if user choice is upper case 'S' or lower case
's'
if ch == 'S' or ch == 's':
# Calls the function to draw
starPattern()
# Checks if user choice is upper case 'P' or lower case
'P'
elif ch == 'P' or ch == 'p':
# Calls the function to draw
polygonPattern()
# Checks if user choice is upper case 'Q' or lower case
'q'
elif ch == 'Q' or ch == 'q':
# Calls the function to draw
squarePattern()
else:
print("Invalid move. Try again!")
Sample Output: