Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am trying to work on slice operator in the jupyter notebook but I am getting an error:

File "C:\Users\adescamp\Skycraper\skycraper.py", line 20, in <module>

    item = plateau[debut:fin]

TypeError: slice indices must be integers or None or have an _index_ method

I am getting error in the line item = plateau[debut:fin]

from math import sqrt

plateau = [2, 3, 1, 4, 1, 4, 2, 3, 4, 1, 3, 2, 3, 2, 4, 1]

taille = sqrt(len(plateau))

# Division en lignes

L = []

i = 1

while i < taille:

    fin = i * taille

    debut = fin - taille

    item = plateau[debut:fin]

    L.append(item)

    i += 1

1 Answer

0 votes
by (36.8k points)

If you observe the variables debut and fin they are float, not an integer. Since taille is float. You need to change the variables into an integer.

item = plateau[int(debut):int(fin)]

Or you can change taille into an integer.

taille = int(sqrt(len(plateau)))

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

Browse Categories

...