Python Projects | Create Snake Game Step By Step In Python For Beginners - playproduction.de

Python Projects | Create Snake Game Step By Step In Python For Beginners

Tech2 etc
Views: 97441
Like: 1714
🎁15 Cool Python Projects For You & You Should Try👇

LEARN HOW TO MAKE A SIMPLE SNAKE GAME STEP BY STEP IN PYTHON. THIS WILL BE A BEGINNER LEVEL PROJECT.

* If you would like to leave a tip you can do so below, thanks *
PayPal:
Source Code:

⌚Chapters
0:00 Introduction
0:09 Snake Game Demo
0:54 Importing Python Libraries – Starting To Code
1:43 Creating User Interface
2:55 Creating The Border(Danger Zone For the game)
5:09 Creating Scoring System
5:24 Creating Snake
6:40 Creating Food
7:54 Creating Final Score
9:18 Defining Snake Movements
12:59 Binding Keyboard Shortcuts
14:24 Creating Main Loop / Functionalities
25:08 Facing / Solving Errors (Important)
27:36 Snake Game Output

Need any help? Join my Discord:

📜Book I Follow For Learning Python
==============================
📚Python Crash Course:
📒Learning Python (For Starting):
📓Python Automating Programming:
📚Python Programming For Beginners:
📒Python for Data Analysis:

⭐️ Merch ⭐️
👕 Merchandise: tech2-etc.creator-spring.com/

If you enjoyed this video, then please please 👍LIKE and SUBSCRIBE this channel & press the bell icon for future videos.
Thank you.

=============
SUPPORT ME 💪
=============
🎀 Donate Me By PayPal:

🎁 Support me on Patreon for exclusive episodes, discord and more!

☕ Buy Me A Coffee:

===================
Recommended Videos
===================
✅ Create Fully Professional Responsive Animated Website Using HTML & CSS …

✅ Create Netflix Responsive Landing Page Clone With Html and CSS

✅ Ultra Responsive Portfolio Website from Scratch Using Bootstrap Html CSS

==========================
Recommended Course (Playlist)
==========================
✅ Complete Bootstrap Designs:

✅ Web Development Tutorials:

✅ Responsive Web Design Tutorials:

✅ Python Projects:

===============================
Connect with me & get daily updates👇
===============================
Discord:
Instagram:
FB (Personal):
FB Page:
FB Group:

——————————-Track————————–
Music provided by : NoCopyrightSounds
Watch: …
Free Download / Stream:

#pythonprojects #snakegame #pygame #python #projects

106 Comments

  1. Hello broh! i've a problem, when i run the code i can se the screen, but when i try to click any direction key nothing happens… What can i do to solve this?

  2. Hi sir, this program is not working in jupyter notebook 📔, need a suggestion for this pls..

  3. bro i like your content, btw why can't i install the turtle in my terminal

  4. i cant get the food its just taking 1 food only..so that's why my score is always 1..please tell me solution

  5. At line 89 , if snake.direction == "right":
    I am getting " indentationerror : unindent does not match any outer indentation level
    Pls help me!

  6. Bro whenever the game is starting I press the arrow then the snake goes in the direction but when I press different arrow it is not changing direction. I'll send you the code pls check it .
    # import packages
    import turtle
    import random
    import time

    # creating screen
    screen = turtle.Screen()
    screen.title("SNAKE GAME")
    screen.setup(width=700, height=700)
    screen.tracer(0)
    screen.bgcolor("#1d1d1d")

    # creating border
    turtle.speed(5)
    turtle.pensize(4)
    turtle.penup()
    turtle.goto(-310, 250)
    turtle.pendown()
    turtle.color("red")
    turtle.forward(600)
    turtle.right(90)
    turtle.forward(500)
    turtle.right(90)
    turtle.forward(600)
    turtle.right(90)
    turtle.forward(500)
    turtle.penup()
    turtle.hideturtle()

    # score
    score = 0
    delay = 0.1

    # snake
    snake = turtle.Turtle()
    snake.speed()
    snake.shape("square")
    snake.color("green")
    snake.penup()
    snake.goto(0, 0)
    snake.direction = "stop"

    #food
    fruit = turtle.Turtle()
    fruit.speed(0)
    fruit.shape("square")
    fruit.color("white")
    fruit.penup()
    fruit.goto(30, 30)

    old_fruit = ()

    #scoring
    scoring = turtle.Turtle()
    scoring.speed(0)
    scoring.color("white")
    scoring.penup()
    scoring.hideturtle()
    scoring.goto(0, 300)
    scoring.write("Score:", align="center", font=("Courier", 25, "bold"))

    # define how to move
    def snake_go_up():
    if snake.direction != "down":
    snake.direction = "up"

    def snake_go_down():
    if snake.direction != "up":
    snake.direction = "down"

    def snake_go_left():
    if snake.direction != "right":
    snake.direction = "left"

    def snake_go_right():
    if snake.direction != "left":
    snake.direction = "right"

    def snake_move():
    if snake.direction == "up":
    y = snake.ycor()
    snake.sety(y + 20)
    if snake.direction == "down":
    y = snake.ycor()
    snake.sety(y – 20)
    if snake.direction == "left":
    x = snake.xcor()
    snake.setx(x + 20)
    if snake.direction == "right":
    x = snake.xcor()
    snake.setx(x – 20)

    # keyboard binding
    screen.listen()
    screen.onkeypress(snake_go_up, "Up")
    screen.onkeypress(snake_go_down, "Down")
    screen.onkeypress(snake_go_left, "Left")
    screen.onkeypress(snake_go_right, "Right")

    # mainloop
    while True:
    screen.update()

    # snake and fruit collision
    if snake.distance(fruit) < 20:
    x = random .randint(-290, 270)
    y = random.randint(-240, 240)
    fruit.goto(x, y)
    scoring.clear()
    score +=1
    scoring.write("Score: {}".format(score), align="center", font=("Courier", 25, "bold"))
    delay -= 0.001

    # creating new foods
    new_fruit = turtle.Turtle()
    new_fruit.speed(0)
    new_fruit.shape("square")
    new_fruit.color("red")
    new_fruit.penup()
    old_fruit = append(new_fruit)

    # adding ball to snake

    for index in range(len(old_fruit) -1, 0, -1):
    a = old_fruit[index -1].xcor()
    b = old_fruit[index -1].ycor()

    old_fruit[index].goto(a, b)

    if len(old_fruit) > 0:
    a = snake.xcor()
    b = snake.ycor()
    old_fruit[0].goto(a, b)
    snake_move()

    # snake & border collision
    if snake.xcor() > 200 or snake.xcor() < -300 or snake.ycor() > 240 or snake.ycor() < -240:
    time.sleep(1)
    screen.clear()
    screen.bgcolor("turquoise")
    scoring.goto(0, 0)
    scoring.write(" GAME OVER n Your score is {}".format(score), align="center", font=("Courier", 30, "bold"))

    # snake collision
    for food in old_fruit:
    if food.distance(snake) < 20:
    time.sleep(1)
    screen.clear()
    screen.bgcolor("turquoise")
    scoring.goto(0, 0)
    scoring.write(" GAME OVER n Your score is {}".format(score), align="center", font=("Courier", 30, "bold"))

    time.sleep(delay)

    turtle.Terminator()

  7. TECH 2etc your amazing thanks very much have helped me alot in learning

  8. Hello Buddy ,
    I can't play this game. Even if I press any key and I try in both system (Mac and Windows) but the same problem game does not start.

  9. Hello master they need the application to run this program this game or not?
    If need the application pls give the link for download the app.

  10. My problem,at line 7, in <module>
    screen = turtle.screen( )
    Attribute Error: module 'turtle' has no attribute 'screen'.
    So, help me

  11. Sir there is Error in code. In
    ## snake and border collision
    Line no 150
    Screen.clear()
    👆🏻 here it is showing Error. Please help how to fix this.

  12. HI question; when I play the game, i can't move for some reason, do you know why? I have followed everything in the video. Great vid btw

  13. When you make those kinds of videos can you explain each line of code and what it does, it will be more beneficial.. thank you

  14. Bro I have problem in line 118 can u plz tell me how to solve?

  15. When I press and key the snake does not move, I followed all of your steps and your fixes hut still nothing, and it says my line 88 is wrong the screen.update() and I don't know how to fix it, please help

  16. Bro, pls help me, I am getting error, Traceback (most recent call last):

    File "C:UsersRishittPycharmProjectssnakegamemain.py", line 121, in <module>

    old_fruit = append(new_fruit)

    NameError: name 'append' is not defined

  17. Steve Minecraft Edits and Respects Shorts says:

    Hi Thanks for recording it is working I wrote all the words carefully
    But I want that, For example I played and touched the line and lose the game and it write GAME OVER YOUR SCORE IS …
    then I have to exit and play again, But I want that press ENTER button and back to game not exiting

  18. I copy all the code .Why don't turn right and left after the snake has passed the border. I hope you can help me

  19. why the snake can't move in any direction , even tho i followed all the steps and fixed the errors

  20. i have a problem that when i take the food the head is seperated from the body

  21. Hi, you're great, I did everything step by step, but when I start the game, everything looks as it should, but I can't move with the snake, would you please advise me?

  22. Thank you for the amazing vedio everything is working except that my snake can only eat 1 food. For some reason the snake can't eat 2nd and it just goes past the 2nd food.

  23. bro turtle.Terminator() error
    it says code is unreachable

  24. My snake wont move. I checked all the snake_move functions and it still didint work

  25. Hi the video was nice but as I open the game it shows game over your score was 0 but i didn't even play the game and in terminal box it show your application has been destroyed pls tell me what to do

  26. This everything doesnt work it is work of edit

  27. it was amazing even tho when my snake eats an apple his speed goes to the moon and idk how to fix it

  28. Sir for some reason this error is showing and the game doesn't even open. please help me fix it

    screen.onekeypress(snake_go_down, "Down")

    AttributeError: '_Screen' object has no attribute 'onekeypress' (error)

  29. I did everything, but on line 117, something happened with the speed. I don’t know what it was, my code was the same as yours, pls help

  30. hi
    i tried to start but it shows error
    in line 3 where i typed import turtle
    i can't find the problem except it doesnt turn gray

  31. hi I tried to do this but I have a problem in line 39 about speed it say line 39, in <module>

    snake.speed()

    AttributeError: 'list' object has no attribute 'speed'

  32. sir , i have problems in line 60 i cant run the code, what do i need to do, ive followed your code precisely, its still not run.

    ps:beginner here.

  33. Is this only for pc or we can play this game in Android?

  34. I finish it, but it shows up for a second then goes away, why does this happen

  35. Main loop is not working for me
    While True but it's not working

  36. AttributeError: partially initialized module 'turtle' has no attribute 'title' (most likely due to a circular import). Did you mean: 'turtle'?

    error

Leave a Reply

Your email address will not be published.