Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dealer_cards = []
- player_cards = []
- import random
- while len(dealer_cards) != 2:
- dealer_cards.append(random.randint(1, 11))
- if len(dealer_cards) == 2:
- print("The dealer has X &", dealer_cards[1])
- while len(player_cards) != 2:
- player_cards.append(random.randint(1, 11))
- if len(player_cards) == 2:
- print("You have ", player_cards)
- if sum(dealer_cards) == 21:
- print("The dealer has 21 and wins!")
- elif sum(dealer_cards) > 21:
- print("The dealer has busted!")
- while sum(player_cards) < 21:
- action_taken = str(input("Do you want to stay or hit? "))
- if action_taken == "hit":
- player_cards.append(random.randint(1, 11))
- print("you now have a total of " + str(sum(player_cards)) + " from these cards ", player_cards)
- else:
- print("The dealer has a total of " + str(sum(dealer_cards)) + " with ", dealer_cards)
- print("You have a total of " + str(sum(player_cards)) + " with ", player_cards)
- if sum(dealer_cards) > sum(player_cards):
- print("The dealer wins!")
- else:
- print("Congratulations, you win!")
- break
- if sum(player_cards) > 21:
- print("You BUSTED! The dealer wins.")
- elif sum(player_cards) == 21:
- print("You have 21! You win!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement