- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
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 turtleimport timeimport randomdelay = 0.1score = 0high_score = 0# Screen setupwn = turtle.Screen()wn.title("Snake Game")wn.bgcolor("green")wn.setup(width=600, height=600)wn.tracer(0)# Snake headhead = turtle.Turtle()head.speed(0)head.shape("square")head.color("black")head.penup()head.goto(0, 0)head.direction = "stop"# Foodfood = turtle.Turtle()food.speed(0)food.shape("circle")food.color("red")food.penup()food.goto(0, 100)segments = []# Score displaypen = 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 functionsdef 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 bindingswn.listen()wn.onkeypress(go_up, "w")wn.onkeypress(go_down, "s")wn.onkeypress(go_left, "a")wn.onkeypress(go_right, "d")# Main game loopwhile True:wn.update()# Border collisionif 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 = 0delay = 0.1pen.clear()pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))# Food collisionif 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.001score += 10if score > high_score:high_score = scorepen.clear()pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))# Move body segmentsfor 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 collisionfor 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 = 0delay = 0.1pen.clear()pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("Courier", 24, "normal"))time.sleep(delay)wn.mainloop()Copied!âś•Copy A Simple Snake Game made in Python 3 · GitHub
Snake game in Python brings back so many memories, I remember spending hours tweaking the code just to get the speed right. A buddy who teaches coding told me simple projects like this are the best …
See results only from gist.github.comForks 87
Forks 87 - A Simple Snake Game made in Python 3 · GitHub
Revisions 1
Revisions 1 - A Simple Snake Game made in Python 3 · GitHub
Stars 112
Stars 112 - A Simple Snake Game made in Python 3 · GitHub
Contact
We would like to show you a description here but the site won’t allow us.
Discover Gists · Github
GitHub Gist: instantly share code, notes, and snippets.
Jarvissilva937
GitHub Gist: star and fork jarvissilva937's gists by creating an account on GitHub.
Naqiiabbas
GitHub Gist: star and fork naqiiabbas's gists by creating an account on GitHub.
Security
Security - A Simple Snake Game made in Python 3 · GitHub
Simple Printing Function to P…
Simple printing function to print one letter at a time in classic computer style! - …
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 …
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 …
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 …
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 …
Searches you might like
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.
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.
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 …
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 …
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 …