1

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
SashaZd
  • 3,315
  • 1
  • 26
  • 48

2 Answers2

0

If you want to run the game continually comment the break after every if-loop

if dealercount > 21:
        money = 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 <----- breaking out of your while loop
SashaZd
  • 3,315
  • 1
  • 26
  • 48
0

You break at the end of each hand which forces you out of the loop. If you remove the break commands, it will then loop around and go back to the start. After removing the break, you need to say

if (game != 'H'):
    # This loop was not a "Hit Me"
    game = input("What would you like to do? Deal or exit? ")

Since you did not count the cards after reading in game, you will get the wrong count values as well.

You need to redo the code to

  1. Count the initial points for the deal

  2. Decide whether to stand or Hit

  3. Have the dealer decide whether to stand or hit.

  4. Decide if the hand is over

  5. If the hand is over, add the results to the money of the winner (and/or subtract from the loser)

  6. If the hand is over, ask whether to deal or exit

  7. If the choice is deal, go back to the beginning

  8. If the hand is not over go back to step 2

sabbahillel
  • 4,357
  • 1
  • 19
  • 36