Write a program that draws a smiley face!

1 answer

Certainly! Below is a simple Python program that uses the turtle graphics library to draw a smiley face. Make sure you have Python installed along with the turtle module (it comes pre-installed with standard Python distributions).

Here's the code:

import turtle

def draw_circle(color, x, y, radius):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.fillcolor(color)
    turtle.begin_fill()
    turtle.circle(radius)
    turtle.end_fill()

def draw_smiley_face():
    # Set up the turtle
    turtle.speed(2)
    turtle.bgcolor("white")

    # Draw face
    draw_circle("yellow", 0, -100, 100)

    # Draw eyes
    draw_circle("black", -35, 0, 10)  # Left eye
    draw_circle("black", 35, 0, 10)   # Right eye

    # Draw mouth
    turtle.penup()
    turtle.goto(-40, -30)
    turtle.pendown()
    turtle.setheading(-60)  # Direction of the mouth curve
    turtle.circle(40, 120)  # Draw the arc of the mouth

    # Hide the turtle and finish
    turtle.hideturtle()
    turtle.done()

draw_smiley_face()

Instructions to Run the Program:

  1. Copy the code above into a file named smiley_face.py or any name you prefer.
  2. Ensure you have Python installed on your machine.
  3. Run the file using Python from the command line or an IDE that supports Python.

You should see a new window pop up with a cute smiley face drawn using turtle graphics. Enjoy!