Python Forum
why don't i get the answer i want
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why don't i get the answer i want
#5
(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.
Reply


Messages In This Thread
why don't i get the answer i want - by CompleteNewb - Sep-02-2021, 10:59 PM
RE: why don't i get the answer i want - by CompleteNewb - Sep-03-2021, 02:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting the wrong answer, and not sure why riskeay 3 2,093 Nov-05-2020, 08:24 PM
Last Post: deanhystad
  Make the answer of input int and str enderfran2006 2 2,054 Oct-12-2020, 09:44 AM
Last Post: DeaD_EyE
  Keeps looping even after correct answer mcesmcsc 2 1,966 Dec-12-2019, 04:27 PM
Last Post: mcesmcsc
  I'm getting a wrong answer don't know where the bug is 357mag 4 2,872 Jul-07-2019, 11:21 PM
Last Post: DeaD_EyE
  How to answer subprocess prompt Monty 8 17,528 Feb-14-2018, 09:59 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020