0
0
PythonHow-ToBeginner · 3 min read

How to Draw a Star Using Turtle in Python - Simple Guide

You can draw a star in Python using the turtle module by moving the turtle forward and turning it by 144 degrees five times. This creates a five-pointed star shape with simple commands like forward() and right().
📐

Syntax

To draw a star using the turtle module, you use these main commands:

  • turtle.forward(distance): Moves the turtle forward by the specified distance.
  • turtle.right(angle): Turns the turtle clockwise by the specified angle in degrees.
  • turtle.done(): Keeps the window open until you close it.

For a five-pointed star, you repeat moving forward and turning right by 144 degrees five times.

python
import turtle

t = turtle.Turtle()
for _ in range(5):
    t.forward(100)  # Move forward by 100 units
    t.right(144)    # Turn right by 144 degrees

turtle.done()
Output
A window opens showing a five-pointed star drawn by the turtle.
💻

Example

This example draws a simple five-pointed star using the turtle module. It shows how to set up the turtle, draw the star, and keep the window open.

python
import turtle

star = turtle.Turtle()
star.color("blue")
star.pensize(3)

for _ in range(5):
    star.forward(150)
    star.right(144)

star.hideturtle()
turtle.done()
Output
A window opens displaying a blue five-pointed star with thicker lines.
⚠️

Common Pitfalls

Common mistakes when drawing a star with turtle include:

  • Using the wrong turning angle. The correct angle is 144 degrees for a five-pointed star.
  • Not repeating the forward and turn commands exactly five times.
  • Forgetting to call turtle.done(), which closes the window immediately.

Here is an example of a wrong angle and the fix:

python
import turtle

wrong_star = turtle.Turtle()

# Wrong: turning 90 degrees creates a square, not a star
for _ in range(5):
    wrong_star.forward(100)
    wrong_star.right(90)

# Correct: turning 144 degrees creates a star
wrong_star.clear()
for _ in range(5):
    wrong_star.forward(100)
    wrong_star.right(144)

wrong_star.hideturtle()
turtle.done()
Output
First draws a square, then clears and draws a five-pointed star.
📊

Quick Reference

CommandDescription
turtle.forward(distance)Move turtle forward by distance
turtle.right(angle)Turn turtle clockwise by angle degrees
turtle.left(angle)Turn turtle counterclockwise by angle degrees
turtle.color(color)Set the pen color
turtle.pensize(size)Set the pen thickness
turtle.done()Finish drawing and keep window open

Key Takeaways

Use a 144-degree turn to draw a five-pointed star with turtle.
Repeat forward and right turn commands exactly five times.
Always call turtle.done() to keep the drawing window open.
Set pen color and size to customize your star's appearance.
Common errors include wrong angles and missing the done() call.