Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prompts the user to enter the length of the star and draw a

ID: 3825677 • Letter: W

Question

Write a program that prompts the user to enter the length of the star and draw a star, as shown in Figure 3.5a. (Turtle: display a STOP_sign) write a program that displays a STOP sign, as shown in Figure 3.5b. The hexagon is in red and the text is in white. (Turtle: draw the Olympic symbol) write a program that prompts the user to enter the radius of the rings and draws an Olympic symbol of five rings of the same size with the colors blue, black, red, yellow, and green. as shown in Figure 3.5c. (Turtle: paint a smiley face) write a program that paints a smiley face, as shown in Figure 3.6a.

Explanation / Answer

Python code for olympic rings :

import turtle
class MyTurtleOly(turtle.Turtle):
""""""

def __init__(self):
""" Constructor"""
turtle.Turtle.__init__(self, shape="turtle")

  
def drawCircle(self, x, y, radius=50):
"""
Moves the turtle to draw a circle
"""
self.penup()
self.setposition(x, y)
self.pendown()
self.circle(radius)


def drawOlympicSymbol(self):
"""
Iterates to draw the Olympics logo
"""
positions = [(0, 0), (-120, 0), (60,60),
(-60, 60), (-180, 60)]
for position in positions:
self.drawCircle(position[0], position[1])

if __name__ == "__main__":
t = MyTurtleOly()
t.drawOlympicSymbol()
turtle.getscreen()._root.mainloop()


Python code for star :

import turtle
def drawStar(size, color):
angle = 120
turtle.fillcolor(color)
turtle.begin_fill()

for side in range(5):
turtle.forward(size)
turtle.right(angle)
turtle.forward(size)
turtle.right(72 - angle)
turtle.end_fill()
return

drawStar(100, "purple")