1- import os
21import random
32import time
43
@@ -49,51 +48,53 @@ def hit(hand):
4948 hand .append (card )
5049 return hand
5150
52- def clear ():
53- if os .name == 'nt' :
54- os .system ('CLS' )
55- if os .name == 'posix' :
56- os .system ('clear' )
57-
5851def print_results (dealer_hand , player_hand ):
59- clear ()
6052 print ("The dealer has a " + str (dealer_hand ) + " for a total of " + str (total (dealer_hand )))
6153 time .sleep (1 )
6254 print ("You have a " + str (player_hand ) + " for a total of " + str (total (player_hand )))
6355
6456def blackjack (dealer_hand , player_hand ):
6557 if total (player_hand ) == 21 :
6658 print_results (dealer_hand , player_hand )
59+ time .sleep (1 )
6760 print ("Congratulations! You got a Blackjack!\n " )
61+ time .sleep (1 )
6862 play_again ()
6963 elif total (dealer_hand ) == 21 :
7064 print_results (dealer_hand , player_hand )
65+ time .sleep (1 )
7166 print ("Sorry, you lose. The dealer got a blackjack.\n " )
67+ time .sleep (1 )
7268 play_again ()
7369
7470def score (dealer_hand , player_hand ):
7571 if total (player_hand ) == 21 :
7672 print_results (dealer_hand , player_hand )
73+ time .sleep (1 )
7774 print ("Congratulations! You got a Blackjack!\n " )
7875 elif total (dealer_hand ) == 21 :
7976 print_results (dealer_hand , player_hand )
77+ time .sleep (1 )
8078 print ("Sorry, you lose. The dealer got a blackjack.\n " )
8179 elif total (player_hand ) > 21 :
8280 print_results (dealer_hand , player_hand )
81+ time .sleep (1 )
8382 print ("Sorry. You busted. You lose.\n " )
8483 elif total (dealer_hand ) > 21 :
8584 print_results (dealer_hand , player_hand )
85+ time .sleep (1 )
8686 print ("Dealer busts. You win!\n " )
8787 elif total (player_hand ) < total (dealer_hand ):
8888 print_results (dealer_hand , player_hand )
89+ time .sleep (1 )
8990 print ("Sorry. Your score isn't higher than the dealer. You lose.\n " )
9091 elif total (player_hand ) > total (dealer_hand ):
9192 print_results (dealer_hand , player_hand )
93+ time .sleep (1 )
9294 print ("Congratulations. Your score is higher than the dealer. You win\n " )
9395
9496def game ():
9597 choice = 0
96- clear ()
9798 print ("WELCOME TO BLACKJACK!\n " )
9899 dealer_hand = deal (deck )
99100 player_hand = deal (deck )
@@ -104,7 +105,6 @@ def game():
104105 blackjack (dealer_hand , player_hand )
105106 time .sleep (1 )
106107 choice = input ("Do you want to [H]it, [S]tand, or [F]old: " ).lower ()
107- clear ()
108108 if choice == "h" :
109109 hit (player_hand )
110110 while total (dealer_hand ) < 17 :
@@ -121,4 +121,4 @@ def game():
121121 exit ()
122122
123123if __name__ == "__main__" :
124- game ()
124+ game ()
0 commit comments