Is my first blackjack program a decent start?

November 8, 2026 4 answers
Asked by 29Trestling

I wrote a small Python blackjack game while learning and would appreciate feedback on what works and what I should improve next. Right now, the player can choose to draw once, while the computer does not take a turn.

Answers

r6~Gantry

Yes, itโ€™s a solid beginner project. Youโ€™ve got random cards, input, and comparisons in place, which means youโ€™ve turned the rules into working code. The main gameplay gap is that the player only gets one extra card and the dealer never draws.

A useful next step is to put the repeated actions into functions, then use a loop for drawing cards until the player stands or goes over 21. You donโ€™t need to rewrite everything at once.

29Trestling:

Thanks, that gives me a clear next thing to try.

Reply to this answer
A6+Knurling

One logic bug to fix: in the draw branch, you check whether the player's total is greater than or equal to the dealer's before checking for a tie. Equal scores will match the first condition, so the draw case can never run there. Check equality first, then compare the scores.

Also decide how you want to handle totals above 21. At the moment, those cases fall into the loss branch, but spelling out the bust rule will make the code easier to reason about.

Reply to this answer
Y3~Bitfield

For a first pass, getting a playable version down is the hard part. The repeated print statements are a good refactoring target: make a function that displays both hands or the final result, and call it instead of copying those lines into each branch.

Another small improvement is to use clearer variable names, such as player_cards and dealer_cards, rather than numbering every card. Then totals can be calculated from the lists instead of writing a separate expression for each hand.

Q!Trestle.4:

That sounds more manageable than starting over. Iโ€™ll try moving the cards into lists first.

Reply to this answer
9F+Pewter

One rules detail to keep in mind: your card list allows an 11, but blackjack usually treats an ace as 1 when counting it as 11 would push the hand over 21. Otherwise some hands that should be playable will look like busts.

You can add that behavior after the basic turn loop works. Small steps are fine here. A first version does not have to match every rule perfectly.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions