1
- cards = [ "A" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "J" , "Q" , "K" ]
1
+ # Lab 4: Blackjack Advice
2
2
3
- players_picks = []
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
+ # At this point, assume aces are worth 1. Use the following rules to determine the advice:
7
+
8
+ # Less than 17, advise to "Hit"
9
+ # Greater than or equal to 17, but less than 21, advise to "Stay"
10
+ # Exactly 21, advise "Blackjack!"
11
+ # Over 21, advise "Already Busted"
12
+
13
+ # Print out the current total point value and the advice.
14
+
15
+ # What's your first card? Q
16
+ # What's your second card? 2
17
+ # What's your third card? 3
18
+ # 15 Hit
19
+
20
+ # What's your first card? K
21
+ # What's your second card? 5
22
+ # What's your third card? 5
23
+ # 20 Stay
24
+
25
+ # What's your first card? Q
26
+ # What's your second card? J
27
+ # What's your third card? A
28
+ # 21 Blackjack!
4
29
5
-
6
30
7
- players_picks = print (input (f"What's your first card?: " ))
31
+ # Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
32
+ player_cards = []
8
33
34
+ # First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
9
35
10
- players_picks = print (input (f"What's your second card?: " ))
36
+ for player_card in range (1 , 4 ):
37
+ player_cards .append (input (f"What's your card #{ player_card } : " ).upper ())
11
38
39
+ # At this point, assume aces are worth 1. Use the following rules to determine the advice:
40
+
41
+ # Less than 17, advise to "Hit"
42
+ # Greater than or equal to 17, but less than 21, advise to "Stay"
43
+ # Exactly 21, advise "Blackjack!"
44
+ # Over 21, advise "Already Busted"
45
+
46
+ def summ (nums ):
47
+ 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
+
50
+ for num in nums :
51
+ total = total + cards [num ]
52
+ return total
53
+
54
+ cards_total = summ (player_cards )
55
+
56
+ if cards_total < 17 :
57
+ result = "Hit"
58
+ elif cards_total >= 17 and cards_total < 21 :
59
+ result = "Stay"
60
+ elif cards_total == 21 :
61
+ result = "Blackjack!"
62
+ else :
63
+ result = "Already Busted"
64
+
65
+ # Print out the current total point value and the advice.
12
66
13
- players_picks = print (input ( f"what's your third card?: " ) )
67
+ print (f" { cards_total } is a { result } " )
0 commit comments