When I run my Python script, why do I get the error:
List index out of range
although the index exists in the list? Here is my code:
a=[input()]
b=input()
c=int(input())
d=[a[0], a[2]]
print(d)
When executing it, this is the error:
Traceback (most recent call last):
File "lista.py", line 6, in <module>
d=[a[0], a[2]]
IndexError: list index out of range
Then, I modified my code like this:
a=list(input())
b=str(input())
c=int(input())
new_a = [b, a[1], a[2], c]
print(new_a)
When printing, it does not identify the elements of a
as a list, so when entering, for example:
carro, silla, mesa
pelota
56
The program gives me the result:
['pelota', 'a', 'r', 56]
I want that in position [1] and [2] of the new list go the [1] and [2] of the previous list, in which failure?