Sep-03-2021, 02:58 AM
(This post was last modified: Sep-03-2021, 02:58 AM by CompleteNewb.)
(Sep-03-2021, 12:38 AM)bowlofred Wrote: The problem in your first program is that your card values are strings and they don't sort the way you expect.
>>> playerhand = [['7', 'h'], ['5', 'h'], ['13', 'H'], ['10', 'h'], ['12', 'h'], ['11', 'h'], ['9', 'h']] >>> sorted(playerhand) [['10', 'h'], ['11', 'h'], ['12', 'h'], ['13', 'H'], ['5', 'h'], ['7', 'h'], ['9', 'h']]If the card values were ints, then the sort would be as expected.
>>> playerhand = [[int(r), s] for r,s in playerhand] >>> sorted(playerhand) [[5, 'h'], [7, 'h'], [9, 'h'], [10, 'h'], [11, 'h'], [12, 'h'], [13, 'H']]That's better.
One other thing to think about. Do your straights/suites allow the ace to play both high and low? Is [1, 10, 11, 12, 13] a valid straight?
Well i completely agree with you that my numbers must be integers and I'll change that right now, but the second function does the exact same thing gives me the right answer and they both have the same list to work from, so why does one return '(True, 13)' and the other returns 'None'?
P.S. Yeah, there's an 'elif' statement that takes care of the 'ace' problem. It's written in the function.