# Challenge: Functioning Blackjack Game [closed]

This is kept fairly original:

Write a program that creates a standard blackjack game:

• input "h" means hit or draw another card
• input "s" means stand, or take what you have already

Rules:

• cards values are as follows:

• 2-9 = face value of card

• 10, J, Q, K = 10

• aces = 11 unless player busts, then it's only a 1

• if 2 or more aces are drawn the first is 11, and each one after is a 1

• the bank needs 18-21, and has to draw another card until they are in this range

• this game runs forever

Procedure:

• The player gets 2 cards at the beginning, shown by "Player:" in the console (Example: Player gets 2 and 5 at the beginning. Console output: "Player: 2, 5").
• The cards can be shown in the console by their values (For example: 2, 10, 1 | No need for: 2, K, A), but you can also use the card-names instead. Your choice
• The input by the player is "h" for "hit" and "s" for "stand". Also allowed is 1 and 0
• The bank gets one card at the beginning, shown by "Bank:"
• At the end you get the output "Win", "Lose", "Draw", or "Blackjack", depending on the game

This game is a challenge.

• 1. Do we show the bank's other cards and, if so, when? 2. Do we need to pick from some number of shuffled decks in a uniformly random manner, and if so do we need to implement any logic around when these cards get shuffled, like casinos do or may we shuffle every hand? 3. Some people might prefer accepting other input (e.g. 1 for hit 0 for stand) as it'll cut down on boiler-plate code, I'd suggest allowing for this lax input (but it's up to you, of course). [Note: do update the post with any clarifications regarding these queries rather than just answering here in comments :)] Dec 16 '19 at 10:52
• Pretty complex challenge, it could benefit of some time in Sandbox for Proposed Challenges. Dec 16 '19 at 10:55
• I also recommend the sandbox. To get you started there, you need to explain what constitutes Win/Lose/Draw/Blackjack. and what exactly happens after the user answers.
Dec 16 '19 at 10:56
• Oh, and don't forget to state what hitting and standing means. Challenges should be self-contained, and not rely external resources.
Dec 16 '19 at 10:58
• I think this should be tagged as interactive. Dec 16 '19 at 11:13

# Python 3, 574$$\\cdots\$$338 337 bytes

from random import*
e,L,B,P=exit,"Lose","Bank:","Player:"
d=[*range(2,12)]*4+[10]*12
c=d.pop
def h(l,m):
l+=[c()]
if sum(l)>21and 11in l:l[l.index(11)]=1
print(m,*l);return sum(l)
shuffle(d)
b=[]
t=h(b,B)
p=[c()]
u=h(p,P)
u>20<e("Blackjack")
while'h'==input():u=h(p,P)
u>21<e(L)
while t<18:t=h(b,B)
22>t>u<e(L)
u==t<e("Draw")
e("Win")


Try it online!

Saved 34 bytes thanks to @ReinstateMonica!!!

• list(...) can be [*...] Dec 17 '19 at 13:39
• And correct me if I'm wrong, but since you don't ever change the list except its order, can't you take out *4 and change [10]*12 to [10]*3? Dec 17 '19 at 13:44
• @ReinstateMonica Thanks, that's a good one! :-) If we take out the *4 etc then we wouldn't be playing with a full deck! In fact only one suit. So, for instance, two aces could never be in play. Dec 17 '19 at 13:55
• Ah right, right; my head was thinking with choice rather than shuffle. Dec 17 '19 at 14:02