Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. #!/python3
  2.  
  3. import os
  4. import random
  5.  
  6. Jack = 11
  7. Queen = 12
  8. King = 13
  9. Ace = 1
  10. deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]*4
  11.  
  12. def deal(deck):
  13. hand = []
  14. for x in range(2):
  15. random.shuffle(deck)
  16. card = deck.pop()
  17. hand.append(card)
  18. return hand #end of a function
  19.  
  20. def play_again():
  21. again = input("Play with me daddy. (Y/N) : ").lower()
  22. if again == "y":
  23. dealer_hand = []
  24. player_hand= []
  25. deck = deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]*4
  26. game()
  27. else:
  28. sys.exit("Come again soon daddy!")
  29.  
  30. def total(hand):
  31. total = 0
  32. for card in hand:
  33. if card == "11" or card == "12" or card == "13":
  34. total+= 10
  35. elif card == "1"
  36. if total >= 11:
  37. total+= 1
  38. else:
  39. total+= 11
  40. else:
  41. total += cad
  42. return total
  43.  
  44. def spankme(hand):
  45. card = deck.pop()
  46. hand.append(card)
  47. return hand
  48.  
  49. def clear():
  50. if os.name == 'nt':
  51. os.system('CLS')
  52. if os.name == 'posix':
  53. os.system('clear')
  54.  
  55. def print_results(dealer_hand, player_hand):
  56. clear()
  57. print("The dealer has a " + str(dealer_hand) + " for a total of " + str(total(dealer_hand)))
  58. print("You have a " + str(player_hand) + " for a total of " + str(total(player_hand)))
  59.  
  60. ef blackjack(dealer_hand, player_hand):
  61. if total(player_hand) == 21:
  62. print_results(dealer_hand, player_hand)
  63. print("Congratulations daddy! You got a Blackjack!\n")
  64. play_again()
  65. elif total(dealer_hand) == 21:
  66. print_results(dealer_hand, player_hand)
  67. print("Sorry daddy, better luck next time!.\n")
  68. play_again()
  69.  
  70. def score(dealer_hand, player_hand):
  71. if total(player_hand) == 21:
  72. print_results(dealer_hand, player_hand)
  73. print("Congratulations! You got a Blackjack!\n")
  74. elif total(dealer_hand) == 21:
  75. print_results(dealer_hand, player_hand)
  76. print("Sorry, you lose. The dealer got a blackjack.\n")
  77. elif total(player_hand) > 21:
  78. print_results(dealer_hand, player_hand)
  79. print("Sorry. You busted a nut. You lose.\n")
  80. elif total(dealer_hand) > 21:
  81. print_results(dealer_hand, player_hand)
  82. print("Dealer busted a nut. You win!\n")
  83. elif total(player_hand) < total(dealer_hand):
  84. print_results(dealer_hand, player_hand)
  85. print("Sorry. Your score isn't higher than the dealer. You lose.\n")
  86. elif total(player_hand) > total(dealer_hand):
  87. print_results(dealer_hand, player_hand)
  88. print("Congratulations. Your score is higher than the dealer. You win\n")
  89.  
  90. def game():
  91. choice = 0
  92. clear()
  93. print("WELCOME TO NEGROJACK!\n")
  94. dealer_hand = deal(deck)
  95. player_hand = deal(deck)
  96. while choice != "q":
  97. print("The dealer is showing a " + str(dealer_hand[0]))
  98. print("You have a " + str(player_hand) + " for a total of " + str(total(player_hand)))
  99. blackjack(dealer_hand, player_hand)
  100. choice = raw_input("Do you want to [H]it, [S]tand, or [Q]uit: ").lower()
  101. clear()
  102. if choice == "h":
  103. hit(player_hand)
  104. while total(dealer_hand) < 17:
  105. hit(dealer_hand)
  106. score(dealer_hand, player_hand)
  107. play_again()
  108. elif choice == "s":
  109. while total(dealer_hand) < 17:
  110. hit(dealer_hand)
  111. score(dealer_hand, player_hand)
  112. play_again()
  113. elif choice == "q":
  114. print "Bye!"
  115. exit()
  116.  
  117. if __name__ == "__main__":
  118. game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement