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


  • 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


    • 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.

  • 7
    \$\begingroup\$ 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 :)] \$\endgroup\$ Dec 16 '19 at 10:52
  • 8
    \$\begingroup\$ Pretty complex challenge, it could benefit of some time in Sandbox for Proposed Challenges. \$\endgroup\$
    – manatwork
    Dec 16 '19 at 10:55
  • 5
    \$\begingroup\$ 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. \$\endgroup\$
    – Adám
    Dec 16 '19 at 10:56
  • 9
    \$\begingroup\$ Oh, and don't forget to state what hitting and standing means. Challenges should be self-contained, and not rely external resources. \$\endgroup\$
    – Adám
    Dec 16 '19 at 10:58
  • 1
    \$\begingroup\$ I think this should be tagged as interactive. \$\endgroup\$
    – Arnauld
    Dec 16 '19 at 11:13

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

from random import*
def h(l,m):
 if sum(l)>21and 11in l:l[l.index(11)]=1
 print(m,*l);return sum(l)
while t<18:t=h(b,B)

Try it online!

Saved 34 bytes thanks to @ReinstateMonica!!!

  • \$\begingroup\$ list(...) can be [*...] \$\endgroup\$
    – squid
    Dec 17 '19 at 13:39
  • \$\begingroup\$ 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? \$\endgroup\$
    – squid
    Dec 17 '19 at 13:44
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Noodle9
    Dec 17 '19 at 13:55
  • \$\begingroup\$ Ah right, right; my head was thinking with choice rather than shuffle. \$\endgroup\$
    – squid
    Dec 17 '19 at 14:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.