Snake Game In Python - Python Beginner Tutorial - playproduction.de

Snake Game In Python – Python Beginner Tutorial

Patrick Loeber
Views: 214466
Like: 3187
Implement the famous Snake game in this beginner tutorial! Learn also how to use the curses module to build terminal applications. This tutorial is aimed at beginners. You will learn about different data structures (e.g. lists and tuples) and how to implement the game logic with different control flows (e.g. while loop / if-statements).

~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~
✅ Write cleaner code with Sourcery: *

Get my Free NumPy Handbook:

⭐ Join Our Discord :

📓 ML Notebooks available on Patreon:

If you enjoyed this video, please subscribe to the channel:
▶️ :

You can find the code here:

Curses doc:

Original Code:

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

🖥️ Website:
🐦 Twitter –
✉️ Newsletter –
📸 Instagram –
🦾 Discord:
▶️ Subscribe:

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅿 Patreon –

# Python

———————————————————————————————————-
* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏

128 Comments

  1. i wish i would have read the comments before i started.

  2. To be honest this helped me a lot thanks keep it up

  3. I dont understand, the code seems just updating/drawing (by addch() method) snake's head & tail, how did the middle ones updates accordingly??

  4. What to do for windows? There is no 'curses' module in windows. And my pip is not working for some reason

  5. This tutorial really need to be updated, I do agree with @Mithchell Bergman, this video seem catered to get more views then actually teaching about python.

  6. every time I paste the code it says error

  7. it keeps saying redirection is not supported
    help

  8. idk if this is happening to anyone else but Pycharm keeps saying that there is something wrong with my Line 1 idk whats happening?

  9. I followed along with the code, but for some reason this is not working with my mac keyboard. I am able to get the program started but, it doesn't move

  10. I'm getting this error

    LINES value must be >= 2 and <= 117: got 1

    initscr(): Unable to create SP

    Any idea on how to fix it?(Sorry I'm new to python)

  11. Sick, thanks for the tutorial. Will improve the code a little myself tho 😀

  12. sir please help me, the code run successfully, but I couldn't play it. I pressed the up/left/right/down key, it doesn't move the snake..

  13. Very nice video for me to kill time while lock down at home!

  14. I believe I followed step by step but still came back with the error codes

    PS C:UsersUserPycharmProjectspythonProject3> Python snake-1.py

    Traceback (most recent call last):

    File "C:UsersUserPycharmProjectspythonProject3snake-1.py", line 1, in <module>

    import curses

    File "C:UsersUserPycharmProjectspythonProject3curses.py", line 4, in <module>

    curses.initscr()

    AttributeError: partially initialized module 'curses' has no attribute 'initscr' (most likely due to a circular imp

    ort)

    PS C:UsersUserPycharmProjectspythonProject3>

  15. Guys download a Avacada app for python then open spyder that’s the app he is using

  16. where are you coding in is it in pycharm or something else
    couse idk where to actually make the python game

  17. Hi, I keep getting this error.

    win = curses.newwin(WINDOW_HEIGHT, WINDOW_WIDTH, 0, 0) # rows, columns

    _curses.error: curses function returned NULL

    I'm trying to run it in PyCharm but through the terminal? By typing python snake.py

    A few people online are saying curses doesn't work with an IDE and needs a terminal… but it says terminal on PyCharm and those answers are a few years old, so not sure if a terminal has now been added?

    Any idea what the problem is? Or do I need to run this through cmd?
    Thanks

  18. very cool! thanks for the tutorial. I have liked and subed

  19. thanks for sharing! I understand this is much simplified for the tutorial purpose. but just want to point out that food loop gives me so much cringe.

  20. I got this error File "c:/Users/hp/Desktop/Snake game.py", line 19

    print(f''Final score = {score}'')

    ^

  21. I have a problem in line 26 , it say invalide character in identifier , could you help me please?

  22. Strongify ...(wait 4 summer holiday) says:

    This was very helpful
    Thanks

  23. Hi. I like the way you created this game. Now, do you have an idea on how I can add a second snake on the same board simultaneously?

  24. Hey bro, I typed "pip install window-curses" but it showed this after I click enter:
    "'pip' is not recognized as an internal or external command, operable program or batch file."
    Can you help me?

  25. hey, ive tried following your tutorial step by step, and it worked fine, but the code dosent detect any keys, if its the arrows or if its ESC.
    i even tried copy pasting your code, and it didnt work as well.
    im using Pycharm on Windows 10 Pro, how can i fix this?

  26. I ran your code on replit… it says that "break" is outside loop. How do i solve it

  27. on line 17 the curses fuction returned NULL
    win = curses.newwin(WINDOWS_HEIGHT, WIDOWS_WIDTH, 0 ,0)

    someone mind helping me?

  28. It would have been more helpful if you could explain what each thing does rather than just making ourselves to understand the whole thing.

  29. In one tutorial i found on google, the part that generates the snake's 'food' in random locations is as follows:

    if Snake_Head_Location_X == Food_Square_Location_X and Snake_Head_Location_Y== Food_Square_Location_Y:

    Food_Square_Location_X = round(random.randrange(0, WIDTH – Size_Of_Snake) / 10.0) * 10.0

    Food_Square_Location_Y= round(random.randrange(0, HEIGHT – Size_Of_Snake) / 10.0) * 10.0

    Can someone explain to me why it was divided and multiplied by 10?

  30. I am planning on taking my career path through python, and coding in general.
    Line 38 gives me another syntax error, this is why I might not take this as my career path.

  31. it doesnt show me the window when i run it and im only at the beggining

Leave a Reply

Your email address will not be published.