-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob42.py
More file actions
39 lines (36 loc) · 882 Bytes
/
Copy pathprob42.py
File metadata and controls
39 lines (36 loc) · 882 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
29
30
31
32
33
34
35
36
37
38
39
"""
Blackjack Counting
Find the best possible score of a hand. Return 'Bust' if
no scoring results in a hand of less than 21.
"""
__author__ = 'Vince'
def blackjack_scorer(hand):
"""
Takes a hand as an array and returns a blackjack score.
:param hand:
:return score:
"""
aces = 0
score = 0
for card in hand:
try:
score += int(card)
except ValueError:
if card == 'A':
aces += 1
else:
score += 10
best = score + aces
test = best
if aces != 0:
test = score + 11 + aces - 1
if best < test <= 21:
return test
elif best > 21:
return "Bust"
else:
return best
with open('test.txt') as data_file:
N = int(data_file.readline())
for i in range(N):
print blackjack_scorer(data_file.readline().split()),