Reputation: 127
I am trying to write a program about poker game and for the comparison part I called (returned) multiples values for each set up.
In this case, I returned an array, one of them was a boolien and one of them was an integer. But when I tried to use them in another function I get an error ('bool' object is not subscriptable) and I dont know why. My whole code is nearly 150 line and for running it you ll need extra file so I ll share some parts of it.
these are the set up parts for each combination
def straight(n):
F = converter(n)
if consecutive(F) == True:
return [True, F[0]]
return False
def full_house(n):
F = converter(n)
if len(set(F)) == 2:
for i in F:
if F.count(i) == 3:
return [True, i]
return False
this is the part where I will rank them
def ranking(n, k):
if n == "AKQJT" and flush(k) == True:
return 9
elif straight(n)[0]== True and flush(k) == True:
return [8,straight(n)[1]]
elif four_kind(n)[0]== True:
return [7,four_kind(n)[1]]
elif (full_house(n))[0]== True:
return [6,full_house(n)[1]]
elif flush(k) == True:
return 5
elif (straight(n))[0]== True:
return [4,straight(n)[1]]
for example when I try
print(ranking("44447","DDDDD"))
I get an error
elif straight(n)[0]== True and flush(k) == True: line ...
TypeError: 'bool' object is not subscriptable
But interstingly when I try the straight flush (the second elif part tests it). For example,
print(ranking("23456","DDDDD")
I get an answer like
[8,6]
which its the true answer but then again I get the same error.
Upvotes: 1
Views: 137
Reputation: 282
Please checkout what you are returning through straight(n). I believe in this case you are trying to return False. So, Boolean is not subscript-able.
If you get get straight(n) as False. You cannot write if-elif conditions to verify their cases. You need to design nested loops for cases straight(n) is False and straight(n) is not equal to False.
Upvotes: 1
Reputation:
In the default case, you do not return an array:
return False
Change it to something like
return [False, None]
or whatever makes sense for your situation.
Upvotes: 2