Hi
I have been working on a blackjack program and i have hit a brick wall as one of my Global assignments isn't working for some reason
import random
class Cards(object):
def __init__(self):
global cards
global player
global comp
global comp_tot
global playert
cards = {2:4,3:4,4:4,5:4,6:4,7:4,8:4,9:4,10:16,'ace':4}
player = []
playert = 0
comp_tot=0
comp = []
print playert,'hi'
print "The Game is Blackjack"
def draw(self):
f = cards.keys()
a = random.choice(cards.keys())
cards[a]-=1
if cards[a] == 0:
del cards[a]
if len(cards)==0:
print "out of cards"
return False
return a
def First_turn(self):
print comp_tot
print cards
print player
print playert
card1=self.draw()
card2=self.draw()
card2='ace'
if card1 is not 'ace' and card2 is not 'ace':
player.append(card1)
player.append(card2)
value=card1+card2
print "your cards are:",card1,"and",card2
print value
playert+=value
else:
player.append(card1)
player.append(card2)
count =0
if card1 =='ace':
count = 'c1'
if playert+11>21:
val = 1
else:
val=11
elif card2 == 'ace':
count ='c2'
if playert + 11 >21:
val = 1
else:
val = 11
c = Cards()
c.First_turn()
every other global variable works exept playert. Any help on how to fix this would be appreciated. Oh also the error i am getting goes like this
Traceback (most recent call last):
File "C:/Documents and Settings/Paul/My Documents/Python/projects/Blackjack/jack1.0.py", line 61, in <module>
c.First_turn()
File "C:/Documents and Settings/Paul/My Documents/Python/projects/Blackjack/jack1.0.py", line 30, in First_turn
print playert
UnboundLocalError: local variable 'playert' referenced before assignment
oh and also sorry for all the added prints, they were for debugging purposes