Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- randomize = random.randint(0,13)
- total = 100 #Initial user funds
- cardLeft = 52
- balance = 100
- #Given card deck dict to be used. Store the cards and qty of each card
- dictCardDeck ={'1':4,'2':4,'3':4,'4':4,'5':4,'6':4,'7':4,'8':4,'9':4,'10':4,'J':4,'Q':4,'K':4}
- print("Welcome to the Card Game")
- print("The player and computer will each be given 3 cards randomly from the card deck.")
- print("The value of the 3 cards will be summed up (10,J,Q,K are considered 0 value) to give your card value")
- print("The max card value is 10. Example the 3 cards - 9,Q,6 gives a card value of 5")
- print("The one with a bigger card value wins the game.")
- print("It will be a draw when Player and computer both have the same card value")
- print("Card dispensed will be removed from the deck.")
- print("A game requires minimum of 6 cards.")
- print("A new deck will be use if there is insufficient cards")
- print()
- print()
- print()
- print("Current card deck",dictCardDeck)
- print("Number of cards left = %s"%cardLeft)
- print()
- print("You have $%d"%balance)
- bets = int(input("Place your bets (0 to quit):"))
- print("Computer Cards:")
- a = random.choice(list(dictCardDeck.keys()))
- b = random.choice(list(dictCardDeck.keys()))
- c = random.choice(list(dictCardDeck.keys()))
- print(a, b, c)
- if a == "J" or a == "Q" or a == "K":
- a = 0
- if b == "J" or b == "Q" or b == "K":
- b = 0
- if c == "J" or c == "Q" or c == "K":
- c = 0
- cardvalue1 = a + b + c
- print("Card value = %d"%cardvalue1)
- print()
- print("Your Cards:")
- d = random.choice(list(dictCardDeck.keys()))
- e = random.choice(list(dictCardDeck.keys()))
- f = random.choice(list(dictCardDeck.keys()))
- print(d, e, f)
- if d == "J" or d == "Q" or d == "K":
- d = 0
- if e == "J" or e == "Q" or e == "K":
- b = 0
- if f == "J" or f == "Q" or f == "K":
- f = 0
- cardvalue2 = d + e + f
- print("Card value = %d"%cardvalue2)
- if cardvalue1 == cardvalue2:
- print("It's a draw game.")
- elif cardvalue1 > cardvalue2:
- print('Computer Won. You lost $%d'%bets)
- balance = balance - bets
- elif cardvalue1 < cardvalue2:
- print("You won. You won $%d"%bets)
- balance = balance + bets
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement