2
2
3
3
import random
4
4
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
6
6
7
7
random .shuffle (deck )
8
8
9
+ print (
10
+ " ********************************************************** " )
11
+ print (
12
+ " Welcome to the game Casino - BLACK JACK ! " )
13
+ print (
14
+ " ********************************************************** " )
9
15
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
17
18
18
19
while 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 ])
25
24
26
25
# Displaying the Player's cards
27
26
while 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 )
34
32
35
33
if 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 ()
38
36
39
37
if 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 ()
42
40
43
41
if sum (d_cards ) == 21 :
44
- print ("***********************Dealer is the Winner !!******************" )
45
- exit ()
42
+ print ("***********************Dealer is the Winner !!******************" )
43
+ exit ()
46
44
47
45
if 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 ()
50
48
51
49
52
50
def 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 !!**********************" )
90
77
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 !!******************" )
91
85
92
86
93
87
while sum (p_cards ) < 21 :
@@ -96,16 +90,14 @@ def dealer_choice():
96
90
if k == 1 :
97
91
random .shuffle (deck )
98
92
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 )
101
95
if sum (p_cards ) > 21 :
102
- print ('*************You are BUSTED !*************\n Dealer Wins !!' )
96
+ print ('*************You are BUSTED !*************\n Dealer Wins !!' )
103
97
if sum (p_cards ) == 21 :
104
- print ('*******************You are the Winner !!*****************************' )
98
+ print ('*******************You are the Winner !!*****************************' )
105
99
106
-
107
- else :
108
- dealer_choice ()
109
- break
110
-
111
100
101
+ else :
102
+ dealer_choice ()
103
+ break
0 commit comments