I would like to loop my poker program 10 times and see how much money the program makes. This is the output I got and then I have to run it again, but the program does not remind the amount of money earned from the previous round. Do you guys have any suggestions?
Dealer has:
D9
Player1, you have:
['HK', 'DQ']
The amount of money player has won so far
0
What would you like to do? H: Hit me, S: Stand? S
Player wins with 20points
Dealer Busted and has: ['D9', 'C3', 'S5']or17points
Player has won : 2euros
Process finished with exit code 0
And I would like to have an extra line with Total earned money at the bottom and the program asks me again the question if I would like to do it again. Where should I start?
Code
from random import shuffle
def card():
card = []
for speci in ['H', 'D', 'S', 'C']:
for number in ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']:
card.append(speci+number)
shuffle(card)
return card
def pointcount(mycards):
counting = 0
acecount = 0
for i in mycards:
if(i[1] == 'J' or i[1] == 'Q' or i[1] == 'K' or i[1] == 'T'):
counting += 10
elif(i[1] != 'A'):
counting += int(i[1])
else:
acecount += 1
if(acecount == 1 and counting >= 10):
counting += 11
elif(acecount != 0):
counting += 1
return counting
def createplayinghands(mydeck):
dealerhand = []
playerhand = []
dealerhand.append(mydeck.pop())
dealerhand.append(mydeck.pop())
playerhand.append(mydeck.pop())
playerhand.append(mydeck.pop())
while(pointcount(dealerhand) <= 16):
dealerhand.append(mydeck.pop())
return [dealerhand, playerhand]
game = ""
mycard = card()
hands = createplayinghands(mycard)
dealer = hands[0]
player = hands[1]
money = 0
while(game != "exit"):
dealercount = pointcount(dealer)
playercount = pointcount(player)
print("Dealer has:")
print(dealer[0])
print("Player1, you have:")
print(player)
print("The amount of money player has won so far")
print(money)
if(playercount == 21):
money += 3
print("Blackjack Player wins")
print("Player has won: " + str(money) + "euros")
break
elif(playercount > 21):
money += 0
print("player Busts with " + str(playercount) + "points")
print("Player has won: " + str(money) + "euros")
break
elif(dealercount > 21):
print("Dealer Busts with " + str(dealercount) + "points")
print("Player has won: " + str(money) + "euros")
break
game = input("What would you like to do? H: Hit me, S: Stand? ")
if(game == 'H'):
player.append(mycard.pop())
elif(dealercount > 21):
money += 2
print("Player wins with " + str(playercount) + "points")
print("Dealer has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break
elif(playercount > dealercount):
money += 2
print("Player wins with " + str(playercount) + "points")
print("Dealer Busted and has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break
elif(playercount == dealercount):
money += 2
print("Tie Player with " + str(playercount) + "points")
print("Dealer has: " + str(dealer) + " or " + str(dealercount) + "poi nts")
print("Player has won : " + str(money) + "euros")
break
else:
money += 0
print("Dealer wins")
print("Dealer has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break