black jack
thnaks for ur help with updating the score, it now works, but i have two main problem, firstly how would i now get the ace to be 1 and 11, and a way of displaying the total hands played at the end of the game.
thanks for the help
below is my code,
thnaks for ur help with updating the score, it now works, but i have two main problem, firstly how would i now get the ace to be 1 and 11, and a way of displaying the total hands played at the end of the game.
thanks for the help
below is my code,
Code:
import random
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
player=[]
computer=[]
random.shuffle(deck) #this will shuffle the cards in the deck
nextCard = 0
player.append(deck[nextCard])
nextCard += 1
player.append(deck[nextCard]) # nextCard is now 1.
nextCard += 1
computer.append(deck[nextCard])
nextCard += 1
computer.append(deck[nextCard])
nextCard += 1
ptotal = sum(player)
ctotal = sum(computer)
print "players hand", player, "\tplayers total value", ptotal #this will display the players hand
#hit or stand,are players options.
def game():
global nextCard
while (True):
options = raw_input ("do you wana [h]it / [s]tand / [q]uit: ")
if options == 'h':
player.append(deck[nextCard])
ptotal = sum(player)
nextCard += 1
print "players hand", player, "\tplayers total value", ptotal
elif options == 's':
ptotal = sum(player)
print "players hand", player, "\tplayers total value", ptotal
break
elif options == 'q':
playAgain = raw_input ("do u wana play again, [y] / [n]")
if playAgain == "y":
game()
elif playAgain == "n":
print "see ya later, bye!"
return
break
while (True):
if ctotal < 16:
computer.append(deck[nextCard])
nextCard += 1
if ptotal > 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "player busted. computer wins"
break
if ctotal > 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "computer busted. player wins"
break
if ctotal == ptotal:
print "computer hand", computer, "\tcomputers total value", ctotal
print "draw. computer wins"
break
if ptotal == 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "player gets a BlackJack. player wins"
break
if ctotal == 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "computer gets a BlackJack. computer wins"
break
if ptotal > ctotal:
if ptotal < 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "player wins"
break
if ctotal > ptotal:
if ctotal < 21:
print "computer hand", computer, "\tcomputers total value", ctotal
print "computer wins"
break
game()
Comment