22
33import random
44
5- deck = [1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ,10 ,10 ,10 ,11 ]* 4
5+ deck = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 10 , 10 , 10 , 11 ] * 4
66
77random .shuffle (deck )
88
9+ print (
10+ " ********************************************************** " )
11+ print (
12+ " Welcome to the game Casino - BLACK JACK ! " )
13+ print (
14+ " ********************************************************** " )
915
10- print (" ********************************************************** " )
11- print (" Welcome to the game Casino - BLACK JACK ! " )
12- print (" ********************************************************** " )
13-
14-
15- d_cards = [] #Initialising dealer's cards
16- p_cards = [] #Initialising player's cards
16+ d_cards = [] # Initialising dealer's cards
17+ p_cards = [] # Initialising player's cards
1718
1819while len (d_cards ) != 2 :
19- random .shuffle (deck )
20- d_cards .append (deck .pop ())
21- if len (d_cards ) == 2 :
22- print ('The cards dealer has are X ' ,d_cards [1 ])
23-
24-
20+ random .shuffle (deck )
21+ d_cards .append (deck .pop ())
22+ if len (d_cards ) == 2 :
23+ print ('The cards dealer has are X ' , d_cards [1 ])
2524
2625# Displaying the Player's cards
2726while len (p_cards ) != 2 :
28- random .shuffle (deck )
29- p_cards .append (deck .pop ())
30- if len (p_cards ) == 2 :
31- print ("The total of player is " ,sum (p_cards ))
32- print ("The cards Player has are " ,p_cards )
33-
27+ random .shuffle (deck )
28+ p_cards .append (deck .pop ())
29+ if len (p_cards ) == 2 :
30+ print ("The total of player is " , sum (p_cards ))
31+ print ("The cards Player has are " , p_cards )
3432
3533if sum (p_cards ) > 21 :
36- print ("You are BUSTED !\n **************Dealer Wins !!******************\n " )
37- exit ()
34+ print ("You are BUSTED !\n **************Dealer Wins !!******************\n " )
35+ exit ()
3836
3937if sum (d_cards ) > 21 :
40- print ("Dealer is BUSTED !\n ************** You are the Winner !!******************\n " )
41- exit ()
38+ print ("Dealer is BUSTED !\n ************** You are the Winner !!******************\n " )
39+ exit ()
4240
4341if sum (d_cards ) == 21 :
44- print ("***********************Dealer is the Winner !!******************" )
45- exit ()
42+ print ("***********************Dealer is the Winner !!******************" )
43+ exit ()
4644
4745if sum (d_cards ) == 21 and sum (p_cards ) == 21 :
48- print ("*****************The match is tie !!*************************" )
49- exit ()
46+ print ("*****************The match is tie !!*************************" )
47+ exit ()
5048
5149
5250def dealer_choice ():
53- if sum (d_cards ) < 17 :
54- while sum (d_cards ) < 17 :
55- random .shuffle (deck )
56- d_cards .append (deck .pop ())
57-
58-
59- print ("Dealer has total " + str (sum (d_cards ))+ "with the cards " ,d_cards )
60-
61- if sum (p_cards ) == sum (d_cards ):
62- print ("***************The match is tie !!****************" )
63- exit ()
64-
65-
66- if sum (d_cards ) == 21 :
67- if sum (p_cards ) < 21 :
68- print ("***********************Dealer is the Winner !!******************" )
69- elif sum (p_cards ) == 21 :
70- print ("********************There is tie !!**************************" )
71- else :
72- print ("***********************Dealer is the Winner !!******************" )
73-
74- elif sum (d_cards ) < 21 :
75- if sum (p_cards ) < 21 and sum (p_cards ) < sum (d_cards ):
76- print ("***********************Dealer is the Winner !!******************" )
77- if sum (p_cards ) == 21 :
78- print ("**********************Player is winner !!**********************" )
79- if sum (p_cards ) < 21 and sum (p_cards ) > sum (d_cards ):
80- print ("**********************Player is winner !!**********************" )
81-
82- else :
83- if sum (p_cards ) < 21 :
84- print ("**********************Player is winner !!**********************" )
85- elif sum (p_cards ) == 21 :
86- print ("**********************Player is winner !!**********************" )
87- else :
88- print ("***********************Dealer is the Winner !!******************" )
89-
51+ if sum (d_cards ) < 17 :
52+ while sum (d_cards ) < 17 :
53+ random .shuffle (deck )
54+ d_cards .append (deck .pop ())
55+
56+ print ("Dealer has total " + str (sum (d_cards )) + "with the cards " , d_cards )
57+
58+ if sum (p_cards ) == sum (d_cards ):
59+ print ("***************The match is tie !!****************" )
60+ exit ()
61+
62+ if sum (d_cards ) == 21 :
63+ if sum (p_cards ) < 21 :
64+ print ("***********************Dealer is the Winner !!******************" )
65+ elif sum (p_cards ) == 21 :
66+ print ("********************There is tie !!**************************" )
67+ else :
68+ print ("***********************Dealer is the Winner !!******************" )
69+
70+ elif sum (d_cards ) < 21 :
71+ if sum (p_cards ) < 21 and sum (p_cards ) < sum (d_cards ):
72+ print ("***********************Dealer is the Winner !!******************" )
73+ if sum (p_cards ) == 21 :
74+ print ("**********************Player is winner !!**********************" )
75+ if sum (p_cards ) < 21 and sum (p_cards ) > sum (d_cards ):
76+ print ("**********************Player is winner !!**********************" )
9077
78+ else :
79+ if sum (p_cards ) < 21 :
80+ print ("**********************Player is winner !!**********************" )
81+ elif sum (p_cards ) == 21 :
82+ print ("**********************Player is winner !!**********************" )
83+ else :
84+ print ("***********************Dealer is the Winner !!******************" )
9185
9286
9387while sum (p_cards ) < 21 :
@@ -96,16 +90,14 @@ def dealer_choice():
9690 if k == 1 :
9791 random .shuffle (deck )
9892 p_cards .append (deck .pop ())
99- print ('You have a total of ' + str (sum (p_cards ))
100- + ' with the cards ' , p_cards )
93+ print ('You have a total of ' + str (sum (p_cards ))
94+ + ' with the cards ' , p_cards )
10195 if sum (p_cards ) > 21 :
102- print ('*************You are BUSTED !*************\n Dealer Wins !!' )
96+ print ('*************You are BUSTED !*************\n Dealer Wins !!' )
10397 if sum (p_cards ) == 21 :
104- print ('*******************You are the Winner !!*****************************' )
98+ print ('*******************You are the Winner !!*****************************' )
10599
106-
107- else :
108- dealer_choice ()
109- break
110-
111100
101+ else :
102+ dealer_choice ()
103+ break
0 commit comments