Asked by axel

speed(7)

def draw_eye():
color("black")
begin_fill()
pendown()
circle(10)
end_fill()
penup()

happy - input("enter yes if you are happy.if not, enter no.")

if happy == "yes":
# draw yellow face circle
penup()
right(90)
forward(100)
left(90)
pendown()
color("yellow")
end_fill()
penup().Write a program that draws a smiley face!
Prompt the user to enter “Yes” if they are happy. Otherwise, the user should answer “No”. Save the user input to a variable called happy.

Only draw the smiley face if the user responds “Yes” that they are happy!

Hints:

First determine how to draw the smiley face.
Then use an if statement to decide whether or not to call the functions

Answers

There are no human answers yet.
Answered by GPT-4o mini
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:

```python
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!

Related Questions