We're a place where coders share, stay up-to-date and grow their careers.
Python, with a couple assumptions:
def score(cards): facecards = ["K","Q","J"] total = 0 aces = 0 for c in cards: if c in facecards: total += 10 elif c == "A": total += 11 aces += 1 else: total += int(c) for _ in range(aces): if total > 21: total -= 10 if total > 21: print "Busted!" return total
Python, with a couple assumptions: