Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/python3
- import os
- import random
- import sys
- deck = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]*4
- def deal(deck):
- hand = []
- for x in range(2):
- random.shuffle(deck)
- card = deck.pop()
- hand.append(card)
- return hand #end of a function
- def play_again():
- again = input("Play with me daddy. (Y/N) : ").lower()
- if again == "y":
- dealer_hand = []
- player_hand= []
- deck = deck = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]*4
- game()
- else:
- sys.exit("Come again soon daddy!")
- def total(hand):
- total = 0
- for card in hand:
- if card == "Jack" or card == "Queen" or card == "King":
- total+= 10
- elif card == "Ace":
- if total >= 11:
- total+= 1
- else:
- total+= 11
- else:
- total += card
- return total
- def spankme(hand):
- card = deck.pop()
- hand.append(card)
- return hand
- def clear():
- if os.name == 'nt':
- os.system('CLS')
- if os.name == 'posix':
- os.system('clear')
- def print_results(dealer_hand, player_hand):
- clear()
- print("The dealer has a " + str(dealer_hand) + " for a total of " + str(total(dealer_hand)))
- print("You have a " + str(player_hand) + " for a total of " + str(total(player_hand)))
- def blackjack(dealer_hand, player_hand):
- if total(player_hand) == 21:
- print_results(dealer_hand, player_hand)
- print("Congratulations daddy! You got a Blackjack!\n")
- play_again()
- elif total(dealer_hand) == 21:
- print_results(dealer_hand, player_hand)
- print("Sorry daddy, better luck next time!.\n")
- play_again()
- def score(dealer_hand, player_hand):
- if total(player_hand) == 21:
- print_results(dealer_hand, player_hand)
- print("Congratulations! You got a Blackjack!\n")
- elif total(dealer_hand) == 21:
- print_results(dealer_hand, player_hand)
- print("Sorry, you lose. The dealer got a blackjack.\n")
- elif total(player_hand) > 21:
- print_results(dealer_hand, player_hand)
- print("Sorry. You busted a nut. You lose.\n")
- elif total(dealer_hand) > 21:
- print_results(dealer_hand, player_hand)
- print("Dealer busted a nut. You win!\n")
- elif total(player_hand) < total(dealer_hand):
- print_results(dealer_hand, player_hand)
- print("Sorry. Your score isn't higher than the dealer. You lose.\n")
- elif total(player_hand) > total(dealer_hand):
- print_results(dealer_hand, player_hand)
- print("Congratulations. Your score is higher than the dealer. You win\n")
- def game():
- choice = 0
- clear()
- print("WELCOME TO NEGROJACK!\n")
- dealer_hand = deal(deck)
- player_hand = deal(deck)
- while choice != "q":
- print("The dealer is showing a " + str(dealer_hand[0]))
- print("You have a " + str(player_hand) + " for a total of " + str(total(player_hand)))
- blackjack(dealer_hand, player_hand)
- choice = input("Do you want to S[p]ankme, Spankme [T]wice, [S]tand, or [Q]uit: ").lower()
- clear()
- if choice == "p":
- spankme(player_hand)
- while total(dealer_hand) < 17:
- spankme(dealer_hand)
- score(dealer_hand, player_hand)
- play_again()
- if choice == "t":
- spankme(player_hand)
- spankme(player_hand)
- while total(dealer_hand) < 17:
- spankme(dealer_hand)
- score(dealer_hand, player_hand)
- play_again()
- elif choice == "s":
- while total(dealer_hand) < 17:
- spankme(dealer_hand)
- score(dealer_hand, player_hand)
- play_again()
- elif choice == "q":
- print("Bye!")
- exit()
- if __name__ == "__main__":
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement