In python I have a score tracker of a poker hand.
Possible card ranks:
A23456789TJQK
Straights of 3 or more cards score 1 per card. Example straight of 4 cards gives you 4 points.
So I have a score:
score = 0
A sorted list of strings (so I don't have to worry about cards at the end of the list having a straight with the beginning) representing the card ranks of my particular hand:
L4
['6', '8', '8', '9', 'T']
# Note: 8, 9, T is a straight. So I want to add 3 to score
But how can I determine if I have a straight?
What I've tried so far:
I tried converting the strings into integers, but then what do I do with the T, J, K, Q, and A? They aren't numbers.
Using strings I get an error:
for i in range(len(L4) - 1):
if(L4[i] is L4[i + 1] + 1):
sC = sC + 1
if(sC >= 3):
score += sC
L4
['6', '8', '8', '9', 'T']
Traceback (most recent call last):
File "myFile.py", line 66, in <module>
if(L4[i] is L4[i + 1] + 1):
TypeError: must be str, not int
Should I convert them to ints or should I try another way? Thanks for help in advance.