0

BLACKJACK: 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

def black_jack(a,b,c):
    if a+b+c <=21:
        return a+b+c
    elif a+b+c >21:
        if (a or b or c) == 11:
            return (a+b+c-10)
        elif (a and b and c)!= 11:
            return 'bust'
result = black_jack(9,9,11)
print(result)
khelwood
  • 55,782
  • 14
  • 81
  • 108
ketan gangal
  • 33
  • 1
  • 8
  • 2
    Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – Asocia May 15 '20 at 10:04
  • 1
    You don't need the first `elif`: the [Law of the Excluded Middle](https://en.wikipedia.org/wiki/Law_of_excluded_middle) guarantees that if `a+b+c <= 21` is false, then `a+b+c > 21` *must* be true; there's no need to check for it. – chepner May 16 '20 at 12:41

3 Answers3

3

you made a mistake in your if and elif condition.

I invite you to go look at this issue, How to test multiple variables against a value to understand how to properly handle boolean conditions.

Cherlepops
  • 71
  • 1
  • 9
3

try this on line 5

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

or statements must be seperated for each argument.

Community
  • 1
  • 1
Jerbearone
  • 31
  • 2
1

as both, @Jerbearone and @Cherlepops pointed out, your mistake is in the tests against equal 11 or not equal 11 lines.

This should work:

def black_jack(a, b, c):
if a + b + c <= 21:
    return a+b+c

elif a + b + c > 21:
    # if (a or b or c) == 11:
    if a == 11 or b == 11 or c == 11:
        return (a+b+c-10)
    # elif (a and b and c) != 11:
    elif a != 11 and b != 11 and c != 11:
        return 'bust'


if __name__ == "__main__":
    # execute only if run as a script
    result = black_jack(9, 9, 11)
    print(result)
imolitor
  • 780
  • 6
  • 12