I have the following code. It is basically a balckjack function. It should return the sum of 3 numbers is less then 21. If bigger and it has 11 as one of the numbers it should deduct 10 from it. If after the deduction the sum is still bigger han 21 it should return 'BUST'. In the training José solved the last part with making in the elif the sum smaller or equal to 31, which of course is a nice way to have then just 'BUST' in an else and not nested into the elif. However I want to do de excercise my way with nesting the 'BUST' into the elif. So far no luck, I am guessing, because of the return I cannot put any condition afterwards.
Do you guys have any solution to make the 'BUST' a sub-condition of the elif? Here is my code, which does not work.
def blackjack(a,b,c):
added = sum([a,b,c])
if added <= 21:
return added
elif added > 21 and 11 in [a,b,c]:
return added -10
busted = added -10
if busted > 21:
return 'BUST'
It should give the following if called:
blackjack(5,6,7) --> 18
blackjack(9,9,9) --> 'BUST'
blackjack(9,9,11) --> 19