import random
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(self):
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
In LINE 58, we keep getting the message unsupported operand type(s) for +: 'int' and 'str'. Why won't saying "for i in hand: sum=sum+i.value" not work, and what are we supposed to do to fix it