Skip to content

Commit f953dae

Browse files
committed
lab04 completed
1 parent 33de4f3 commit f953dae

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

code/kaceyb/python/lab04/lab_04.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,67 @@
1-
cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
1+
# Lab 4: Blackjack Advice
22

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!
429

5-
630

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 = []
833

34+
# First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
935

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())
1138

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.
1266

13-
players_picks = print(input(f"what's your third card?: "))
67+
print(f"{cards_total} is a {result}")

0 commit comments

Comments
 (0)