**Problem :**

I am facing following type error while trying to execute the Python program

**deprecationwarning: object of type <class 'float'> cannot be safely interpreted as an integer.**

- Q&A
- Questions
- Unanswered
- Tags
- Users
- Ask a Question
- Articles
- Interview Questions
- Programming Quiz
- Post An Article

0 votes

Please note the **range()** can only work with integers but the dividing with / operator will always results in a float value:

e.g.

>>> 450 / 10 45.0 >>> range(450 / 10) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'float' object cannot be interpreted as an integer

So please make the value an integer again by following method:

for i in range(int(c / 10)):

or you can use the // floor division operator:

for i in range(c // 10):

0 votes

`for i in range(c/10):`

`for i in range(c // 10):`

`range()`

can only work with integers, but dividing with the `/`

operator always results in a float value:```
>>> 450 / 10
45.0
>>> range(450 / 10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
```

`for i in range(int(c / 10)):`

`//`

floor division operator:`for i in range(c // 10):`

`range`

only supports integers:```
>>> range(15.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: range() integer end argument expected, got float.
>>> range(15)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
>>>
```

However, `c/10`

is a float because `/`

always returns a float.

Before you put it in `range`

, you need to make `c/10`

an integer. This can be done by putting it in `int`

:

`range(int(c/10))`

`//`

, which returns an integer:`range(c//10)`