This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex3_blackjack.py
74 lines (61 loc) · 1.92 KB
/
ex3_blackjack.py
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
from random import randint
def random_card():
"""
Pick a random card
:return: the value of the card
"""
card = randint(1, 11)
if card == 1:
chosen = False
while not chosen:
value = input("Vous avez pioché un AS. 1 ou 11 ? ")
if value == '1':
card = 1
chosen = True
elif value == '11':
card = 11
chosen = True
return card
card_value_player = 0
card_value_ia = 0
picked_card_player = random_card()
print("Vous avez pioché : %d" % picked_card_player)
card_value_player += picked_card_player
picked_card_ia = random_card()
print("L'ordinateur pioche...")
card_value_ia += picked_card_ia
picked_card_player = random_card()
print("Vous avez pioché : %d" % picked_card_player)
card_value_player += picked_card_player
if card_value_player == 21:
print("Blackjack!")
new_card = card_value_player < 21
while new_card:
answer = input("Voulez-vous une nouvelle carte? (carte/je reste)")
if answer == 'carte':
picked_card_player = random_card()
print("Vous avez pioché : %d" % picked_card_player)
card_value_player += picked_card_player
if card_value_player > 21:
print("Vous avez perdu! (> 21)")
new_card = False
elif card_value_player == 21:
print("Vous avez atteint 21!")
new_card = False
elif answer == 'je reste':
new_card = False
else:
print("Svp choisissez entre 'carte' et 'je reste'")
ia_new_card = 17 <= picked_card_ia == 21
while ia_new_card:
card_value_ia += random_card()
if card_value_ia > 21:
print("Vous avez gagné! (IA > 21)")
elif 17 <= card_value_ia <= 21:
ia_new_card = False
if card_value_player > card_value_ia:
print("Vous avez gagné!")
elif card_value_player < card_value_ia:
print("Vous avez perdu!")
else:
print("Egalité")