Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. You can easily create a playable Snake Game in Python using the built-in turtle module. This version is simple, runs locally, and uses keyboard controls to move the snake.

    import turtle
    import time
    import random

    delay = 0.1
    score = 0
    high_score = 0

    # Screen setup
    wn = turtle.Screen()
    wn.title("Snake Game")
    wn.bgcolor("green")
    wn.setup(width=600, height=600)
    wn.tracer(0)

    # Snake head
    head = turtle.Turtle()
    head.speed(0)
    head.shape("square")
    head.color("black")
    head.penup()
    head.goto(0, 0)
    head.direction = "stop"

    # Food
    food = turtle.Turtle()
    food.speed(0)
    food.shape("circle")
    food.color("red")
    food.penup()
    food.goto(0, 100)

    segments = []

    # Score display
    pen = turtle.Turtle()
    pen.speed(0)
    pen.color("white")
    pen.penup()
    pen.hideturtle()
    pen.goto(0, 260)
    pen.write("Score: 0 High Score: 0", align="center", font=("Courier", 24, "normal"))

    # Movement functions
    def go_up():
    if head.direction != "down":
    head.direction = "up"
    def go_down():
    if head.direction != "up":
    head.direction = "down"
    def go_left():
    if head.direction != "right":
    head.direction = "left"
    def go_right():
    if head.direction != "left":
    head.direction = "right"

    def move():
    if head.direction == "up":
    head.sety(head.ycor() + 20)
    if head.direction == "down":
    head.sety(head.ycor() - 20)
    if head.direction == "left":
    head.setx(head.xcor() - 20)
    if head.direction == "right":
    head.setx(head.xcor() + 20)

    # Keyboard bindings
    wn.listen()
    wn.onkeypress(go_up, "w")
    wn.onkeypress(go_down, "s")
    wn.onkeypress(go_left, "a")
    wn.onkeypress(go_right, "d")

    # Main game loop
    while True:
    wn.update()

    # Border collision
    if abs(head.xcor()) > 290 or abs(head.ycor()) > 290:
    time.sleep(1)
    head.goto(0, 0)
    head.direction = "stop"
    for segment in segments:
    segment.goto(1000, 1000)
    segments.clear()
    score = 0
    delay = 0.1
    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    # Food collision
    if head.distance(food) < 20:
    x = random.randint(-290, 290)
    y = random.randint(-290, 290)
    food.goto(x, y)

    new_segment = turtle.Turtle()
    new_segment.speed(0)
    new_segment.shape("square")
    new_segment.color("grey")
    new_segment.penup()
    segments.append(new_segment)

    delay -= 0.001
    score += 10
    if score > high_score:
    high_score = score

    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    # Move body segments
    for i in range(len(segments) - 1, 0, -1):
    x = segments[i - 1].xcor()
    y = segments[i - 1].ycor()
    segments[i].goto(x, y)

    if segments:
    segments[0].goto(head.xcor(), head.ycor())

    move()

    # Self collision
    for segment in segments:
    if segment.distance(head) < 20:
    time.sleep(1)
    head.goto(0, 0)
    head.direction = "stop"
    for segment in segments:
    segment.goto(1000, 1000)
    segments.clear()
    score = 0
    delay = 0.1
    pen.clear()
    pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))

    time.sleep(delay)

    wn.mainloop()
    Copied!
    Feedback
  2. python snake game

    You learned how to create the game snake in Python along with concepts such as collision detection, image loading and event handling. Many things could be …

  3. Create a Snake-Game using Turtle in Python

    Feb 18, 2026 · The Snake Game is a classic arcade game first released in 1976 by Gremlin Industries and published by Sega. The goal is simple to control the …

  4. How to Make a Snake Game in Python - The Python Code

    Learn how to build a classic snake game using Pygame in Python. This detailed step-by-step tutorial explains how to initialize Pygame, generate food for the …

  5. Build Snake Game in Python Using Turtle Module

    Jun 26, 2025 · Learn how to build a complete Snake game in Python using Turtle. This step-by-step guide covers movement, collisions, scoring, and customization …

  6. Snake Game Using Python - 101 Computing

    Mar 21, 2024 · In this Python programming challenge, we are going to revisit the classic game called Snake. In this game, the player controls a snake using the arrow keys of the keyboard.

  7. Implementing the Snake Game in Python - Towards Data Science

    Feb 10, 2026 · In this article, we will learn to build a simple Snake Game. We will use Python’s turtle module in order to generate this game.

  8. Python Programming Snake Game: A Comprehensive Guide

    Apr 5, 2025 · By the end of this guide, you'll have a solid understanding of the fundamental concepts involved in creating a Snake game, how to use relevant Python libraries, common practices, and best …

  9. Pythonade - Building a Snake Game with Python and Pygame

    In this tutorial, we'll build a classic Snake game using Python's Pygame library, focusing on vector graphics for a clean, retro aesthetic. We'll break this down into four progressive stages, each adding …

  10. Create Classic Snake Game in Python – Learn …

    Jan 29, 2025 · In this tutorial, we will cover the key aspects of game development, including handling user input, detecting collisions, creating game objects, and …