I'm just starting to learn python and my first project is a text based Blackjack game.
pHand being the players hand and pTotal being the total of the players cards.
The for loop seems to be exiting after the first iteration. When I print pTotal and pHand out after the loop, it shows only the first card's value every time.
Code:
import random
f = open('Documents/Python/cards.txt', 'r')
deck = f.read().splitlines()
f.close
pTotal = 0
cTotal = 0
random.shuffle(deck)
pHand = [deck[0], deck[1]]
cHand = [deck[2]]
for x in pHand:
if deck[x][0] == '1' or deck[x][0] == 'J' or deck[x][0] == 'Q' or deck[x][0] == 'K':
pTotal += 10
elif deck[x][0] == 'A':
pTotal += 11
else:
pTotal += int(deck[x][0])
Any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire