0

Hi all. Please edit/add/help me make this blackjack program work. Thank you.

```
class Card:
def __init__(self, suit, rank):
self.rank = rank
self.suit = suit
if self.rank == 1:
self.rank = "Ace"
self.value = 11
elif self.rank == 11:
self.rank = "Jack"
self.value = 10
elif self.rank == 12:
self.rank = "Queen"
self.value = 10
elif self.rank == 13:
self.rank = "King"
self.value = 10
elif 2 <= self.rank <= 10:
self.rank = str(self.rank)
self.value = self.rank
if self.suit == 1:
self.suit = "Clubs"
if self.suit == 2:
self.suit = "Spades"
if self.suit == 3:
self.suit = "Diamonds"
if self.suit == 4:
self.suit = "Hearts"
self.cardname = self.rank + " of " + self.suit
deck = []
for suit in range(1,5):
for rank in range(1,14):
deck.append(Card(suit,rank)
class Player:
def player_turn():
hand = []
for cards in range(0,2):
a = random.choice(deck)
hand.append(a)
deck.remove(a)
print "This is your hand:"
for card in hand:
print card.cardname,
print "Would you like to hit or stay?"
response= raw_input("Type either 'hit' or 'stay'")
while response =="hit":
card=random.choice(deck)
hand.append(card)
deck.remove(card)
print "Your next card is", card.cardname
sum = 0
for i in hand:
sum=sum+i.value
if sum > 21:
break
print "Would you like to hit or stay?"
response = raw_input("Type either 'hit' or stay'")
sum=0
for i in hand:
sum=sum+i.value
if sum > 21:
return "You lose. You Busted", sum
else:
return "This is your score: ", sum
class Dealer:
def computer_turn():
dealerhand = []
for cards in range(0,2):
a = random.choice(deck)
hand.append(a)
deck.remove(a)
sum = 0
for i in dealerhand:
sum = sum+i.value
while sum < 17
card = random.choice(deck)
dealerhand.append(card)
deck.remove(card)
sum = sum+card.value
if sum > 21:
return "You won! The dealer busted"
return sum
```

*Edited
by Nick Evan*: Fixed formatting