-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_blackjack.py
More file actions
93 lines (71 loc) · 2.16 KB
/
1_blackjack.py
File metadata and controls
93 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import art
import random
cards = [11,2,3,4,5,6,7,8,9,10,10,10]
play = True
def scores(hand):
score = 0
for card in hand:
score += card
return score
def no_blackjack(player, machine):
global game
if scores(player) == 21 or scores(machine) == 21:
if scores(machine) == 21:
print(f"Computer has {machine}, it's a blackjack, you have lost")
game = False
else:
print(f"You have {player}, it's a blackjack, you won")
game = False
def deal(hand):
hand.append(random.choice(cards))
def over21(hand):
global game
if scores(hand) > 21:
if 11 in hand:
if scores(hand) - 10 > 21:
print(f"{hand} has lost")
game = False
else:
hand.append(-10)
def score_comparison (hand1, hand2):
global game
if scores(hand1) > scores(hand2):
print(f"{hand1} vs {hand2}")
print("You have won")
game = False
if scores(hand1) == scores(hand2):
print(f"{hand1} vs {hand2}")
print("It's a tie")
game = False
if scores(hand1) < scores(hand2):
print(f"{hand1} vs {hand2}")
print("You have lost")
game = False
spaces = "\n" *50
while play:
print(art.logo)
user = []
computer = []
game = True
while game:
for _ in range(2):
deal(user)
deal(computer)
no_blackjack(user, computer)
print(f"Here are your cards: {user}, current score: {scores(user)}")
print(f"Here is the computer's first card: {computer[0]}.")
while input("Do you want to draw another card? y/n") == "y":
deal(user)
print(f"You have drawned a card: {user[-1]}, you are now at {scores(user)}.")
no_blackjack(user, computer)
over21(user)
while scores(computer) < 17:
deal(computer)
no_blackjack(user, computer)
over21(computer)
score_comparison(user, computer)
if input("Do you want to play again? y/n") == "y":
print(spaces)
else:
print("Thanks for playing")
play = False