Hello everybody,
I know I'm really new to the site, but I really need your help. I've been developing a blackjack game over the last few days and I'm a bit stuck know.
If you guys could help me with a few things:
1. For some reason, the game never allows you to win. I've checked my program multiple times, but I can't figure out why.
2. Whenever I try to print the sum functions, I always get this odd message. Something like, "Instance of function at x93483".
3. If you could help me make a running chip count through the program that also would be amazing.
I've really worked very hard so far and I really just need this last bit of help!!
Thank you!!
I know I'm really new to the site, but I really need your help. I've been developing a blackjack game over the last few days and I'm a bit stuck know.
If you guys could help me with a few things:
1. For some reason, the game never allows you to win. I've checked my program multiple times, but I can't figure out why.
2. Whenever I try to print the sum functions, I always get this odd message. Something like, "Instance of function at x93483".
3. If you could help me make a running chip count through the program that also would be amazing.
I've really worked very hard so far and I really just need this last bit of help!!
Thank you!!
Code:
import random
class Card:
def __init__(self, suit, rank, value):
self.rank = rank
self.suit = suit
self.value= value
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.value = self.rank
self.rank = str(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):
for value in range(2,12):
deck.append(Card(suit,rank,value))
class Player:
def total(self):
total = 100
print "You have 100 chips"
bet=raw_input("How many chips would you like to bet?")
total= int(total)-int(bet)
return total
def bet(self):
print "You have ", total, "chips. How many would you like to bet?"
bet = raw_input()
return bet
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
psum=0
for i in hand:
psum=int(i.value) + psum
if psum > 21:
break
print "Would you like to hit or stay?"
response = raw_input("Type either 'hit' or stay'")
return psum
def sum(self):
sum=0
for i in hand:
sum= int(i.value)+sum
return sum
class Dealer:
def computer_turn(self):
dealerhand = []
for cards in range(0,2):
a = random.choice(deck)
dealerhand.append(a)
deck.remove(a)
dsum = 0
for i in dealerhand:
dsum = int(i.value)+dsum
while dsum < 17:
card = random.choice(deck)
dealerhand.append(card)
deck.remove(card)
dsum = int(card.value)+dsum
return dsum
def sum(self):
sum=0
for i in dealerhand:
sum= int(i.value)+sum
return sum
print "Would you like to play?"
answer = raw_input("'Yes' or 'No'")
while answer == "Yes":
p = Player()
d = Dealer()
p.total()
p.player_turn()
d.computer_turn()
if p.sum > d.sum and p.sum <= 21:
print "You won! Here is the dealer's score."
print d.sum
else:
print "You lost. Here is the computer's score.", d.sum
print "Would you like to play again?"
answer = raw_input("'Yes' or 'No'")
Comment