Sure! Below is a corrected and complete program that draws a smiley face using Python's turtle graphics. The program prompts the user for input on whether they are happy and only draws the face if the user responds "yes".
Here's the code:
import turtle
# Function to draw an eye
def draw_eye(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color("black")
turtle.begin_fill()
turtle.circle(10) # Draws the eye
turtle.end_fill()
# Function to draw a smile
def draw_smile():
turtle.penup()
turtle.goto(-20, -10)
turtle.pendown()
turtle.setheading(-60) # Set the orientation of the turtle
turtle.circle(20, 120) # Draws a smile arc
# Function to draw the smiley face
def draw_smiley_face():
# Draw the face circle
turtle.penup()
turtle.goto(0, -100) # Position for face
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.circle(100) # Draws the face
turtle.end_fill()
# Draw the eyes
draw_eye(-35, 40) # Left eye
draw_eye(35, 40) # Right eye
# Draw the smile
draw_smile()
# Main program starts here
turtle.speed(7)
happy = input("Enter 'yes' if you are happy. If not, enter 'no': ").strip().lower()
if happy == "yes":
draw_smiley_face()
turtle.hideturtle() # Hide the turtle after drawing
turtle.done() # Complete the drawing
Explanation of the Code:
- The program imports the
turtle
graphics module. - A function
draw_eye(x, y)
draws an eye at a specific(x, y)
coordinate. - The
draw_smile()
function creates a smile arc. - The
draw_smiley_face()
function combines the face, eyes, and smile into a complete smiley face. - The program checks the user's response. If they enter "yes", it calls the
draw_smiley_face()
function to create the smiley face. - Finally,
turtle.done()
is called to finish the drawing and keep the turtle graphics window open.
Make sure you have the turtle graphics library available in your Python environment. You can copy and paste this code into your Python interpreter or an IDE that supports turtle graphics. Enjoy creating your smiley face!