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! 🙏

126 Comments

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

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

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

  4. 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.

  5. every time I paste the code it says error

  6. it keeps saying redirection is not supported
    help

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

  8. 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

  9. 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)

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

  11. 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..

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

  13. 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>

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

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

  16. 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

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

  18. 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.

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

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

    ^

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

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

    This was very helpful
    Thanks

  22. 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?

  23. 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?

  24. 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?

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

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

    someone mind helping me?

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

  28. 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?

  29. 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.

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

  31. bro is professor poopypants from captain underpants lol good video

Leave a Reply

Your email address will not be published.