
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! 🙏
03.12.2022
To be honest this helped me a lot thanks keep it up
I used the python to create the python
I dont understand, the code seems just updating/drawing (by addch() method) snake's head & tail, how did the middle ones updates accordingly??
Are you using pycharm for this game
What to do for windows? There is no 'curses' module in windows. And my pip is not working for some reason
How is this a beginner tutorial????
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.
every time I paste the code it says error
it keeps saying redirection is not supported
help
Pleased after watching this
when it doesn't work: :')
idk if this is happening to anyone else but Pycharm keeps saying that there is something wrong with my Line 1 idk whats happening?
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
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)
Sick, thanks for the tutorial. Will improve the code a little myself tho 😀
are you using replit to code
what are you using
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..
Very nice video for me to kill time while lock down at home!
Thanks man your the best
https://youtu.be/hjk8Y3Qa4mo
What terminal are you using ?
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>
good
7:55
Guys download a Avacada app for python then open spyder that’s the app he is using
Do we to first install python
where are you coding in is it in pycharm or something else
couse idk where to actually make the python game
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
It won’t let me move now
does it work in 2022?
What IDE is that?
what IDE are you typing this code in?
very cool! thanks for the tutorial. I have liked and subed
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.
I got this error File "c:/Users/hp/Desktop/Snake game.py", line 19
print(f''Final score = {score}'')
^
I have a problem in line 26 , it say invalide character in identifier , could you help me please?
This was very helpful
Thanks
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?
great guy isubs
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?
IDE ?
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?
I ran your code on replit… it says that "break" is outside loop. How do i solve it
on line 17 the curses fuction returned NULL
win = curses.newwin(WINDOWS_HEIGHT, WIDOWS_WIDTH, 0 ,0)
someone mind helping me?
It would have been more helpful if you could explain what each thing does rather than just making ourselves to understand the whole thing.
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?
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.
it doesnt show me the window when i run it and im only at the beggining
bro is professor poopypants from captain underpants lol good video