Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import random
  2. randomize = random.randint(0,13)
  3. total = 100 #Initial user funds
  4. cardLeft = 52
  5. balance = 100
  6. #Given card deck dict to be used. Store the cards and qty of each card
  7. 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}
  8.  
  9. print("Welcome to the Card Game")
  10. print("The player and computer will each be given 3 cards randomly from the card deck.")
  11. print("The value of the 3 cards will be summed up (10,J,Q,K are considered 0 value) to give your card value")
  12. print("The max card value is 10. Example the 3 cards - 9,Q,6 gives a card value of 5")
  13. print("The one with a bigger card value wins the game.")
  14. print("It will be a draw when Player and computer both have the same card value")
  15. print("Card dispensed will be removed from the deck.")
  16. print("A game requires minimum of 6 cards.")
  17. print("A new deck will be use if there is insufficient cards")
  18. print()
  19. print()
  20. print()
  21. print("Current card deck",dictCardDeck)
  22. print("Number of cards left = %s"%cardLeft)
  23. print()
  24. print("You have $%d"%balance)
  25. bets = int(input("Place your bets (0 to quit):"))
  26. print("Computer Cards:")
  27. a = random.choice(list(dictCardDeck.keys()))
  28. b = random.choice(list(dictCardDeck.keys()))
  29. c = random.choice(list(dictCardDeck.keys()))
  30. print(a, b, c)
  31. if a == "J" or a == "Q" or a == "K":
  32. a = 0
  33. if b == "J" or b == "Q" or b == "K":
  34. b = 0
  35. if c == "J" or c == "Q" or c == "K":
  36. c = 0
  37.  
  38. cardvalue1 = a + b + c
  39. print("Card value = %d"%cardvalue1)
  40. print()
  41. print("Your Cards:")
  42. d = random.choice(list(dictCardDeck.keys()))
  43. e = random.choice(list(dictCardDeck.keys()))
  44. f = random.choice(list(dictCardDeck.keys()))
  45. print(d, e, f)
  46. if d == "J" or d == "Q" or d == "K":
  47. d = 0
  48. if e == "J" or e == "Q" or e == "K":
  49. b = 0
  50. if f == "J" or f == "Q" or f == "K":
  51. f = 0
  52. cardvalue2 = d + e + f
  53. print("Card value = %d"%cardvalue2)
  54. if cardvalue1 == cardvalue2:
  55. print("It's a draw game.")
  56. elif cardvalue1 > cardvalue2:
  57. print('Computer Won. You lost $%d'%bets)
  58. balance = balance - bets
  59. elif cardvalue1 < cardvalue2:
  60. print("You won. You won $%d"%bets)
  61. balance = balance + bets
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement