I am trying to write a simple BlackJack code to try understanding how to use if, elif, else and Blocking. The question is as follow:
#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'
I wrote this code:
a = int(input("a"))
b = int(input("b"))
c = int(input("c"))
sum = a + b + c
total = 0
if a in range(1, 12) and b in range(1, 12) and c in range(1, 12):
if sum <= 21:
print(sum)
elif (sum > 21) and (a or b or c == 11):
sum = sum - 10
print(sum)
if sum > 21:
print("Busted")
else:
print("One of which ain't in the range; range should be between 1-11")
I should test the result for the following inputs
a b c : 5, 6, 7 --> 18
a b c : 9, 9, 9 --> "BUSTED"
a b c : 9, 9, 11. --> 19
For the first and last one it gives me the right result. Yet the second one it gives me 17 which is wrong. For some reason the code is reading it > 21 and one of the variable is 11.. which is not right since all are 9
Also, I am not sure if the condition in this line is written right
elif (sum > 21) and (a or b or c == 11):
One last thing is there a better/shorter way to write this line:
if a in range(1, 12) and b in range(1, 12) and c in range(1, 12):
I tried to write it as
if (a, b, c) in range(1,12):
However, i believe python is reading it as tuples, which should be the case..
I am total noob I know.. but trying my best to learn you all :)
Thanks