Skip to content

Commit 4a96e14

Browse files
committed
Lab 4 Blackjack Advice Version 1 complete
1 parent 06a9a4b commit 4a96e14

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Lab 4: Blackjack Advice
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.
6+
# At this point, assume aces are worth 1. Use the following rules to determine the advice:
7+
8+
deck_one = ['A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K']
9+
deck_two = ['A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K']
10+
deck_three = ['A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K','A','2','3','4','5','6','7','8','9','10','J','Q','K']
11+
12+
import random
13+
14+
random.shuffle(deck_one)
15+
random.shuffle(deck_two)
16+
random.shuffle(deck_three)
17+
18+
first_card = random.choice(deck_one)
19+
second_card = random.choice(deck_two)
20+
third_card = random.choice(deck_three)
21+
22+
print(f"Welcome to Blackjack.","Your cards are:",first_card,second_card,third_card)
23+
24+
if first_card == 'A':
25+
first_card = int('1')
26+
elif first_card == 'J':
27+
first_card = int('10')
28+
elif first_card == 'Q':
29+
first_card = int('10')
30+
elif first_card == 'K':
31+
first_card = int('10')
32+
33+
if second_card == 'A':
34+
second_card = int('1')
35+
elif second_card == 'J':
36+
second_card = int('10')
37+
elif second_card == 'Q':
38+
second_card = int('10')
39+
elif second_card == 'K':
40+
second_card = int('10')
41+
42+
if third_card == 'A':
43+
third_card = int('1')
44+
elif third_card == 'J':
45+
third_card = int('10')
46+
elif third_card == 'Q':
47+
third_card = int('10')
48+
elif third_card == 'K':
49+
third_card = int('10')
50+
51+
first_card = (int(first_card))
52+
second_card = (int(second_card))
53+
third_card = (int(third_card))
54+
55+
card_totals = (first_card + second_card + third_card)
56+
57+
if card_totals < 17:
58+
print("You should hit.")
59+
elif card_totals in range (17, 21):
60+
print("You should stay.")
61+
elif card_totals > 21:
62+
print("Sorry you busted.")
63+
elif card_totals > 20:
64+
print("Congratulations, Blackjack!")
65+
66+
# Version 2 (optional)
67+
68+
# Aces can be worth 11 if they won't put the total point value of both cards over 21. Remember that you can have multiple aces in a hand.
69+
# Try generating a list of all possible hand values by doubling the number of values in the output whenever you encounter an ace.
70+
# For one half, add 1, for the other, add 11. This ensures if you have multiple aces that you account for the full range of possible values.

0 commit comments

Comments
 (0)