Python Forum
How to resolve Index Error in my code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to resolve Index Error in my code?
#6
Apologies! Let me put the details
Depth 3 is considered as the terminating condition because the tree on which we are implementing this algorithm has a depth of 3. NodeIndex * 2 + i will always be in range because here nodeindex is always zero and only i is incrementing to make nodeindex increase in value.

And sorry index error is initially on line 11.
So for example I put the following inputs :
x = 8 (number of leaf nodes)
scr = { 3, 5, 6, 9, 1, 2, 0, -1 };


1st iteration :

nodeindex=0 , depth = 0, values:[-1]

2nd iteration :

nodeindex=0 , depth = 1, values:[-1]

3rd iteration :

nodeindex=0 , depth = 2, values:[-1]

4th iteration:
nodeindex=0 , depth = 3, values:[-1]

Line 11 runs: return values[nodeIndex]
Value returned to line 20 and finally to line 60.


After this, I see the index error(list out of range) at line 11.
Reply


Messages In This Thread
RE: How to resolve Index Error in my code? - by codify110 - May-22-2021, 10:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyscript index error while calling input from html form pyscript_dude 2 1,015 May-21-2023, 08:17 AM
Last Post: snippsat
  Index error help MRsquared 1 810 May-15-2023, 03:28 PM
Last Post: buran
  [split] How to resolve version conflicts in Python? atonalwilson 1 1,024 May-04-2023, 09:02 AM
Last Post: buran
  How to resolve version conflicts in Python? taeefnajib 0 951 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  How to resolve my problem in Pycharm? bshoushtarian 0 879 Sep-26-2022, 11:45 AM
Last Post: bshoushtarian
  I'm getting a String index out of range error debian77 7 2,397 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 2,021 Feb-21-2022, 08:58 AM
Last Post: deanhystad
  Python Error List Index Out of Range abhi1vaishnav 3 2,361 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  win32com — How to resolve “AttributeError: xlUp” for Excel files? JaneTan 2 4,303 Aug-18-2021, 05:27 AM
Last Post: snippsat
  Index error - columns vs non-column Vinny 3 4,970 Aug-09-2021, 04:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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