1
1
# Lab 4: Blackjack Advice
2
2
3
- # Let's write a python program to give basic blackjack playing advice during a game by asking the player for cards.
4
- # First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
5
- # Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
3
+ # Let's write a python program to give basic blackjack playing advice during a game by asking the player for cards.
4
+ # First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
5
+ # Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
6
6
# At this point, assume aces are worth 1. Use the following rules to determine the advice:
7
7
8
8
# Less than 17, advise to "Hit"
28
28
# 21 Blackjack!
29
29
30
30
31
- # Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
31
+ # Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
32
32
player_cards = []
33
33
34
- # First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
34
+ # First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
35
35
36
36
for player_card in range (1 , 4 ):
37
37
player_cards .append (input (f"What's your card #{ player_card } : " ).upper ())
43
43
# Exactly 21, advise "Blackjack!"
44
44
# Over 21, advise "Already Busted"
45
45
46
+
46
47
def summ (nums ):
47
48
total = 0
48
- cards = {"A" :1 , "2" :2 , "3" :3 , "4" :4 , "5" :5 , "6" :6 , "7" :7 , "8" :8 , "9" :9 , "10" :10 , "J" :10 , "Q" :10 , "K" :10 }
49
-
49
+ cards = {
50
+ "A" : 1 ,
51
+ "2" : 2 ,
52
+ "3" : 3 ,
53
+ "4" : 4 ,
54
+ "5" : 5 ,
55
+ "6" : 6 ,
56
+ "7" : 7 ,
57
+ "8" : 8 ,
58
+ "9" : 9 ,
59
+ "10" : 10 ,
60
+ "J" : 10 ,
61
+ "Q" : 10 ,
62
+ "K" : 10 ,
63
+ }
64
+
50
65
for num in nums :
51
66
total = total + cards [num ]
52
67
return total
53
68
69
+
54
70
cards_total = summ (player_cards )
55
71
56
72
if cards_total < 17 :
@@ -61,7 +77,7 @@ def summ(nums):
61
77
result = "Blackjack!"
62
78
else :
63
79
result = "Already Busted"
64
-
80
+
65
81
# Print out the current total point value and the advice.
66
82
67
83
print (f"{ cards_total } is a { result } " )
0 commit comments