forked from Ada-Activities/tdd-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (22 loc) · 666 Bytes
/
Copy pathmain.py
File metadata and controls
28 lines (22 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
VALID_CARDS = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']
def blackjack_score(hand):
score = 0
if len(hand) > 5:
return "Invalid"
for card in hand:
if card not in VALID_CARDS:
return "Invalid"
if card in ["Jack", "King", "Queen"]:
score += 10
elif isinstance(card, int):
score += card
elif card in ["Ace"] and score <= 10:
score += 11
elif card in ["Ace"] and score > 10:
score += 1
if score > 21:
if "Ace" in hand:
score -= 10
else:
return "Bust"
return score