0

Int object is unsubscriptable.

It only throws the error if the stats denote psionics which is determined by a random number 2-35 of 100. Inorder to get the error you have a 35% chance anytime you run the program. You must run it several times to get the error. https://code.sololearn.com/cqZ9LreXdB7i/?ref=app

12th Sep 2017, 6:25 PM
James Barrow
James Barrow - avatar
1 Odpowiedź
+ 2
In your code on line 18 you define attributes as an empty list: attributes = [] Then you re-define attributes in your for loop as an int on line 22: attributes = random.randint (3, 18) at this point attributes is no longer a list, but an int. you treat it as an int on lines 24, 25, and 27, but then treat it as a list again on lines 31 an 34. 24: attributes = attributes + random.randint (1, 6) 25: print (i, attributes) 27: print(i, attributes) 31: ISP = int(attributes[1]) + random.randint(4, 24) 34: ISP = int(attributes[1]) + random.randint(2, 12) At this point you're trying to access the index of 1 for an int object, which doesn't make sense. This why you are getting an error. To help avoid confusion, simply change line 18 to be an int or None to begin with. : attributes = 0 or attributes = None Then on lines 31 and 34 remove the indexing from the variable: 31: ISP = int(attributes) + random.randint(4, 24) 34: ISP = int(attributes) + random.randint(2, 12) This will fix the Int object is unsubscriptable error that you're getting. You also need to convert ISP into a str() on lines 32 and 35 in order to prevent another error: 32: print ("Major Psionic I.S.P.:" + str(ISP)) 35: print ("Minor Psionic I.S.P.:" + str(ISP))
12th Sep 2017, 8:23 PM
ChaoticDawg
ChaoticDawg - avatar