I was working on a program to make the classic snake game, where the snake goes around eating and growing longer, but every time i try to run it it closes immediately and TypeError: 'float' object cannot be interpreted as an integer, what do I do to fix this?
Most likely it's because of something like this:
floating_point_number = 3.14
for test in range (floating_point_number) :
print ("This will never be printed.")
Which results in this:
Output:
Press ENTER or type command to continue
Traceback (most recent call last):
File "tester.py", line 8, in <module>
for test in range (floating_point_number) :
TypeError: 'float' object cannot be interpreted as an integer
The solution is something like this:
floating_point_number = 3.14
for test in range (int (floating_point_number)) :
print ("This will never be printed.")
Output:
This will never be printed.
This will never be printed.
This will never be printed.
Post your code and the entire error message, including the error trace