Share your repls and programming experiences

← Back to all posts
Blackjack
Alfi06 (4)

After a week of hard work, I kind of perfected the code. Enter your opinion in the comments section. It is pretty much normal blackjack except it does not have kings, queens, jacks or aces.(Still working on that part) but everything else is still normal...

Commentshotnewtop
Spacecraft (99)

Nice work. Here's a few lines of code to help with adding in the face cards-

Create a list:
cards = [2,3,4,5,6,7,8,9,10,'J','Q','K','A']*4 #this will give you 1 deck! add as many decks as you like.

Use random.sample to select the draw:
hand = random.sample(cards,2)

Decrement the deck by the cards you just drew:
for i in range(hand): #Do this for all drawn cards
cards.remove(hand[i])

Sum your hand:

for i in range(hand):
   if hand[i] == int:
     total += hand[i]
   elif hand[i] == 'A':  # This gives the option to use Ace as either 1 or 11.
     if total + 11 > 21:
       total += 1
     else:
       total += 11
   else:
     total += 10

You can probably put together the rest of it. Good luck!

Spacecraft (99)

Also, sorry for the crappy formatting in my post. I'm new here.

Alfi06 (4)

@MarkKohler Its cool. I will work on it. Thanks!!

DynamicSquid (3294)

On line 44 and 117: if result==False, don't do that. Do this: if not result instead. But other than that, cool!

Alfi06 (4)

@DynamicSquid
I'll try that out. Thanks!