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!

happy face

1 answer

Here's a Python program that draws a smiley face using the turtle graphics library. This program asks the user if they are happy and draws a smiley face if the answer is "Yes".

Make sure you have Python installed on your system, and you can run this code in an environment that supports graphics, such as IDLE or a local Python installation.

import turtle

def draw_smiley_face():
    # Draw face
    turtle.penup()
    turtle.goto(0, -100)  # Move the turtle to start drawing the face
    turtle.pendown()
    
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    turtle.circle(100)  # Draw circle for face
    turtle.end_fill()

    # Draw left eye
    turtle.penup()
    turtle.goto(-40, 35)  # Move to the left eye position
    turtle.pendown()
    
    turtle.fillcolor('black')
    turtle.begin_fill()
    turtle.circle(10)  # Left eye
    turtle.end_fill()
    
    # Draw right eye
    turtle.penup()
    turtle.goto(40, 35)  # Move to the right eye position
    turtle.pendown()
    
    turtle.fillcolor('black')
    turtle.begin_fill()
    turtle.circle(10)  # Right eye
    turtle.end_fill()

    # Draw smiling mouth
    turtle.penup()
    turtle.goto(-40, -20)  # Move to the mouth starting point
    turtle.setheading(-60)  # Set the angle for the semi-circle
    turtle.pendown()
    turtle.circle(40, 120)  # Draw mouth

    # Hide the turtle after drawing
    turtle.hideturtle()

# Main program
happy = input("Are you happy? (Yes/No): ").strip().capitalize()

if happy == "Yes":
    turtle.speed(2)  # Set the speed of drawing
    draw_smiley_face()
    turtle.done()  # Finish the drawing
else:
    print("Sorry to hear that! Remember, it's okay to feel sad sometimes.")

Instructions to Run the Program:

  1. Install Python if not already installed.
  2. Make sure you have the turtle module, which is included by default in standard Python installations.
  3. Copy the code into a Python file (e.g., smiley_face.py).
  4. Run the file using Python (e.g., python smiley_face.py).
  5. Follow the prompt to enter "Yes" or "No".

This program will create a window displaying a smiling face if the user responds with "Yes". If the response is "No", it will simply print a message to the console.