Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Issue While Making Simple Basketball Sim Engine

Basically, I have two teams with their starting line-ups and am using a simple formula involving each players Offensive and Defensive rating to determine a score. I plan on expanding on this with time and obviously making the score vary and not always be the same; however, for now I just want to figure out an error I keep getting.

Here is the code:

    #Player Database
    #Player = [OR,DR]
    #Miami Heat
Chris_Bosh = [114-90,103-100]
Udonis_Haslem = [110-90,103-100]
Lebron_James = [125-90,101-100]
Dwayne_Wade = [112-90,103-100]
Mario_Chalmers = [110-90,104-100]
    #San Antonio Spurs
Tim_Duncan = [107-90,95-100]
Tiago_Splitter = [118-90,100-100]
Kawhi_Leonard = [114-90,99-100]
Manu_Ginobili = [107-90,100-100]
Tony_Parker = [116-90,106-100]

#Team Database
MIA = [Chris_Bosh,Udonis_Haslem,Lebron_James,Dwayne_Wade,Mario_Chalmers]
SAS = [Tim_Duncan,Tiago_Splitter,Kawhi_Leonard,Manu_Ginobili,Tony_Parker]
#Engine
def engine():
    #calculation:
    MIA[0[0]] + SAS[0[1]] + MIA[1[0]] + SAS[1[1]] + MIA[2[0]] + SAS[2[1]] + MIA[3[0]] + SAS[3[1]] + MIA[4[0]] + SAS[4[1]] == MIAs
    SAS[0[0]] + MIA[0[1]] + SAS[1[0]] + MIA[1[1]] + SAS[2[0]] + MIA[2[1]] + SAS[3[0]] + MIA[3[1]] + SAS[4[0]] + MIA[4[1]] == SASs
    print ("Miami", MIAs," ", "San Antonio", SASs)
engine()

And here is the error:

Traceback (most recent call last):
  File "C:\Users\Kevin Lewis\Desktop\Kevin\Documents\Python\NBA Sim Engine.py", line 27, in <module>
    engine()
  File "C:\Users\Kevin Lewis\Desktop\Kevin\Documents\Python\NBA Sim Engine.py", line 24, in engine
    MIA[0[0]] + SAS[0[1]] + MIA[1[0]] + SAS[1[1]] + MIA[2[0]] + SAS[2[1]] + MIA[3[0]] + SAS[3[1]] + MIA[4[0]] + SAS[4[1]] == MIAs
TypeError: 'int' object is not subscriptable
like image 315
Kevin02 Avatar asked Apr 24 '26 11:04

Kevin02


1 Answers

This, and all the other indexes that look like it are wrong:

MIA[0[0]]

What were you trying to do, perhaps this?

MIA[0][0]

Notice that MIA[0] returns the 0 position of the MIA list, which also happens to be a list, and if in turn we want the 0 position of that second list, then we have to use the [0] operator again, hence MIA[0][0].

What you wrote won't work, by saying this: 0[0] you're stating that you want the element at the 0 position of 0, but 0 is not a list, it's an integer number, and that's what the error is telling: 'int' object is not subscriptable.

That was the first error. The second error is in the same lines: all the calculation is being lost, because you didn't save it! this (now fixed) line is asking if two values are equal:

MIA[0][0] + SAS[0][1] + MIA[1][0] + SAS[1][1] + MIA[2][0] + SAS[2][1] + MIA[3][0] + SAS[3][1] + MIA[4][0] + SAS[4][1] == MIAs

I'm pretty certain that what you wanted to do here was an assignment, which is written like this:

MIAs = MIA[0][0] + SAS[0][1] + MIA[1][0] + SAS[1][1] + MIA[2][0] + SAS[2][1] + MIA[3][0] + SAS[3][1] + MIA[4][0] + SAS[4][1]
like image 196
Óscar López Avatar answered Apr 27 '26 00:04

Óscar López



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!