This is a program written in Python using Pycharm IDE. Its called snake game. Its three squares joined together to represent a snake the user guides around the screen eat to interact with a dot as food while keeping score. The program runs just fine until it reaches line #37. Detect collision with wall at which time I get an error message. The screen flashes of and on then I get the error message. In the tutorial the program runs fine but unless I’m not seeing something my code is identical to the tutorials. I can’t add the rest of the code to complete the program. What am I getting wrong?
Traceback (most recent call last):
File “main.py”, line 37, in
if snake.head.xcor() > 280 or snake.head.xcor() < -280 or snake.head.ycor() > 280 or snake.head.ycor < -280:
TypeError: ‘<’ not supported between instances of ‘method’ and ‘int’
Hi @QZapper. So glad you are finding our content helpful. Join us at our Replit 101 event where you can get live support for any and all questions that you may have as a new learner.
Without seeing your full repl, I can’t give you a full idea of what may be going on. If you share your repl, it is easier for others to join in and offer help.
Hope to see you at our Replit 101 workshop (offered each month).
I believe xcor and ycor are methods that return the x-coordinate and y-coordinate respectively of the object in question. If that is the case, snake.head.ycor is missing the parenthesis (brackets ‘()’) at the end meaning you are checking if a method is less than -280.
When it rains it pours. I finally got three responses, yours being one. I did get the solution from MattDestroyer. He must have seen the code I Published on Replit. I’m curious about why you couldn’t see it. First time knowing about Repl 101.
Your right , I was missing a set of () on the last ycor. I finally got three responses, yours being one. I did get the solution from MattDestroyer. He must have seen the code I Published on Replit. I’m curious about why you couldn’t see it.
HI @QZapper sometimes Repl Ask users don’t use the same username on Replit. Posting a link to the Repl that you would like the community to look at saves other users time and mistakenly looking at other Repls and attempting to solve issues with them instead.