@RobertDerry/

Blackjack Code-3

Python

Blackjack.

fork
loading
Files
  • main.py
main.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
import random

#initial variables
unused = [2,3,4,5,6,7,8,9,10,11,12,13,1]
used = []

suit = ["Hearts", "Spades","Diamonds","Clubs"]*4

card1 = random.choice(unused)
unused.remove (card1)
used.append (card1)

if card1 == 11:card1="Jack"
if card1 == 12:card1="Queen"
if card1 == 13:card1="King"
if card1 == 1:card1="Ace"

suit = ["Hearts", "Spades","Diamonds","Clubs"]*4
card2 = random.choice(unused)

unused.remove (card2)
used.append (card2)
if card2 == 11:card2="Jack"
if card2 == 12:card2="Queen"
if card2 == 13:card2="King"
if card2 == 1:card2="Ace"

print("\nYou have been dealt: The", card1, "of" , random.choice(suit), "and The", card2, "of" , random.choice(suit),"\n")

if card1 == "Jack" or "Queen" or "King":
  card1 = 10

value1 = int(card1)
value2 = int(card2)
total_val = value1 + value2

print("That makes a total of", total_val, "\n")

towin = 21-total_val
print("You need", towin, "to win!\n")

hit_again = input("Do you want to hit? y/n: ")

while hit_again == "y":
  card3 = random.choice(unused)
  unused.remove (card3)
  used.append (card3)
  value3 = card3
  total_val = total_val + value3
  if card3 == 11:card3="Jack"
  if card3 == 12:card3="Queen"
  if card3 == 13:card3="King"
  if card3 == 1:card3="Ace"
  print("You got given: The", card3, "of", random.choice(suit)) 
  print("That makes a total of", total_val)
  if total_val <= 21:
    hit_again = input("Do you want to hit? y/n: ")
  if total_val > 21:
    print("You have gone bust!")
    break

else:
  print("Your turn is over!")
  print("You got a score of:", total_val)

print(used)