[Python] Solution to BLACKJACK [closed]

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to solve this problem:


    "Given three integers between 1 and 11, if their sum is less than or equal to 21, return their sum. If their sum exceeds 21 and there's an eleven, reduce the total sum by 10. Finally, if the sum (even after adjustment) exceeds 21, return 'BUST'"
    ​

    with this code:

    def blackjack(a,b,c):

    bj = a+b+c
    bja = 0
    el = False

    if a == 11 or b == 11 or c== 11:
    el = True

    if bj <= 21:
    return bj

    elif bj > 21 and el == True:
    bja = bj-10
    return bja

    elif bja > 21:
    return "BUST"


    For the first the first two parts of the problem it works, but when I use it with something like blackjack(11,11,10), where I expect a "BUST" I get the sum which is 22. Could someone tell me why?

    Continue reading...

Compartilhe esta Página