Python Forum
float object can't be interpreted as an integer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
float object can't be interpreted as an integer
#1
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?
Reply
#2
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.
Reply
#3
Post your code and the entire error message, including the error trace
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 2,254 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  TypeError: 'float' object is not callable #1 isdito2001 1 1,965 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: 'float' object is not callable TimofeyKolpakov 3 3,625 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 2,317 May-31-2022, 08:43 PM
Last Post: Gribouillis
  Float Object is not Subscriptable quest 2 3,981 Apr-20-2021, 09:28 AM
Last Post: quest
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 3,439 Aug-25-2020, 03:43 AM
Last Post: micseydel
  timedelta object cannot be interpreted as integer palladium 5 15,937 Jan-30-2020, 02:54 PM
Last Post: palladium
  How to check if user entered string or integer or float?? prateek3 5 13,752 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity
  Converting float (2.0) to integer(2) Raj_Kumar 2 3,388 Dec-07-2019, 11:01 AM
Last Post: DeaD_EyE
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 4,745 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020