Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List out of range error
#1
Hi guys,
N=3 (will be 2 at most in the loop I want to create)
T=5 (will start from 2 in the loop I want to create)
I want to print:
x(1)(2),I(1)(1)
x(1)(3),I(1)(2)
x(1)(4),I(1)(3)
x(1)(5),I(1)(4)
x(2)(2),I(2)(1)
x(2)(3),I(2)(2)
x(2)(4),I(2)(3)
x(2)(5),I(2)(4)

I am getting list index out of range error , can you help me or fix it ?
[ for ma in range(1,N):
for a in range(2,T+1):
thevars=[x[ma][a],I[ma][a-1]]
print(thevars)
]
Reply
#2
Please show the error code in it's entirety (between the "error" tags) and actual code (between the "code" tags).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
for ma in range(1,N):
for a in range(2,T+1):
thevars=[x[ma][a],I[ma][a-1]]
print(thevars)
Error:
IndexError: list index out of range
I do not know how to do it in error and code tags , sorry , I tried but it did not work[/code]
Reply
#4
That is not the entire error code.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Down I hate "List index out of range" Melen 20 3,376 May-14-2023, 06:43 AM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,941 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  I'm getting a String index out of range error debian77 7 2,383 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,459 May-03-2022, 01:39 PM
Last Post: Anldra12
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,607 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  matplotlib x axis range goes over the set range Pedroski55 5 3,263 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  IndexError: list index out of range rf_kartal 6 2,883 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  Python Error List Index Out of Range abhi1vaishnav 3 2,344 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  IndexError: list index out of range Laplace12 1 2,240 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  python error: bad character range \|-t at position 12 faustineaiden 0 3,712 May-28-2021, 09:38 AM
Last Post: faustineaiden

Forum Jump:

User Panel Messages

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