Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1.  
  2. dealer_cards = []
  3. player_cards = []
  4. import random
  5.  
  6. while len(dealer_cards) != 2:
  7.     dealer_cards.append(random.randint(1, 11))
  8.     if len(dealer_cards) == 2:
  9.       print("The dealer has X &", dealer_cards[1])
  10.  
  11. while len(player_cards) != 2:
  12.     player_cards.append(random.randint(1, 11))
  13.     if len(player_cards) == 2:
  14.       print("You have ", player_cards)
  15.  
  16. if sum(dealer_cards) == 21:
  17.   print("The dealer has 21 and wins!")
  18. elif sum(dealer_cards) > 21:
  19.   print("The dealer has busted!")
  20.  
  21. while sum(player_cards) < 21:
  22.   action_taken = str(input("Do you want to stay or hit?  "))
  23.   if action_taken == "hit":
  24.     player_cards.append(random.randint(1, 11))
  25.     print("you now have a total of " + str(sum(player_cards)) + " from these cards ", player_cards)
  26.   else:
  27.     print("The dealer has a total of " + str(sum(dealer_cards)) + " with ", dealer_cards)
  28.     print("You have a total of " + str(sum(player_cards)) + " with ", player_cards)
  29.     if sum(dealer_cards) > sum(player_cards):
  30.       print("The dealer wins!")
  31.     else:
  32.       print("Congratulations, you win!")
  33.       break
  34.  
  35. if sum(player_cards) > 21:
  36.   print("You BUSTED! The dealer wins.")
  37. elif sum(player_cards) == 21:
  38.   print("You have 21! You win!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement