Python Turtle Snake Game

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

Hi @Qzapper it would be really interesting to see the full code but I think the problem is your use of brackets after xcor and ycor. Try removing all of these and running the program again.

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.

1 Like

You saved me allot of hassle. I’m finally able to continue the program. :+1:

1 Like

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. :slightly_smiling_face:

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. :slightly_smiling_face:

I guess MattDestroyer got at a copy of the tracback that I sent in the post and saw my error.

I guess MattDestroyer got at a copy of the tracback that I sent in the post and saw my error. Still curious ?

You posted the traceback for the error:

It shows the line of code that caused it and I just looked at that line and the error message and figured it out. :slight_smile: Glad I could help.

1 Like

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.