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
#10
def answer(cards: list) -> (bool, int):
    res = None
    def isStraight(cards: list) -> bool:
        nonlocal res
        res = [cards[0]]
        count = 1
        cards.sort()
        for n, card in enumerate(cards):
            if count == 5: return count == 5
            elif n:
                if card-cards[n-1] == 1:
                    count += 1
                    res.append(card)
                else:
                    count = 1
                    res = [card]
        return count == 5
    
    if isStraight(cards):
        return (isStraight(cards), max(res))
    else:
        return (isStraight(cards), None)

def main() -> print:
    player = {'h': [5, 7]}
    table = {'H': [13], 'h': [10, 12, 11, 9]}
    valid = player
    key = table.keys()
    for k in key:
        if k in valid:
            valid[k] = valid[k]+table[k]
        else:
            valid[k] = table[k]
    value = valid.values()
    res = []
    for v in value:
        res = res+v
    if answer(res)[0]:
        print(*answer(res))

if __name__ == "__main__":
    main()
    
Output:
True 13
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 naughtyCat - Sep-03-2021, 09:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting the wrong answer, and not sure why riskeay 3 2,070 Nov-05-2020, 08:24 PM
Last Post: deanhystad
  Make the answer of input int and str enderfran2006 2 2,028 Oct-12-2020, 09:44 AM
Last Post: DeaD_EyE
  Keeps looping even after correct answer mcesmcsc 2 1,936 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,850 Jul-07-2019, 11:21 PM
Last Post: DeaD_EyE
  How to answer subprocess prompt Monty 8 17,452 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