Skip to content
Advertisement

I get a IndexError: list index out of range Error

I´m having some troubles on my code, that implements a function that verifies the lenght of a string and return that string with or without spaces.

If String b >= 15 return b

If strinf < 15 return “number os spaces until len(b)2 + string b

But I get a IndexError: list index out of range Error. I cannot figure out where or why.

Traceback:

============= RESTART: C:UserspboDesktopTrab_04.py =============

ascii_letters = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Traceback (most recent call last):

File “C:UserspboDesktopTrab_04.py”, line 30, in o2.append(a(o1[e]))

IndexError: list index out of range

============= ============= ============= ============= =============

Thanks a lot for any possible help.

JavaScript

Advertisement

Answer

It looks like your indentation is incorrect (see also What is Python Whitespace and how does it work?).

If you change the following:

JavaScript

to:

JavaScript

Then, your code appears to work.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement