@ArnavPoddar/

BlackJack

Python

No description

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
67
68
69
70
71
72
73
74
75
76
import random, time
cards=[1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11]
rules = "n"
Player1="0"
totalc=0
total=0
hitc3=0
scores=[]
x=len(cards)
hitc10=random.randint(1,x-1)
hitc1=cards[hitc10]
cards.remove(hitc1)
x=len(cards)
hitc10=random.randint(1,x-1)
hitc2=cards[hitc10]
cards.remove(hitc2)
totalc=hitc1+hitc2
while totalc < 17:
  x=len(cards)
  hitc10=random.randint(1,x-1)
  hitc3=cards[hitc10]
  cards.remove(hitc3)
  totalc+=hitc3
  print (totalc)
  if totalc > 21:
    Comp="pass"
print ("Welcome to Blackjack.")
rules=input("Do you know how to play?")
rules=rules.lower()
while rules=="n" or rules=="no":
  print ("Let me explain it to you. The goal is to get a total of 21. First, the dealer passes out two cards to each player, as well as to himself. Nobody can see your cards except for you. Cards from 2 to 10 are worth their value, but face cards are also 10 (face cards will automatically convert to 10s in this game). The Ace is either 11, or 1, depending on what the player decides (it will automatically be chosen for you, but an 11 is very rare). On the next turn, you can either decide to hit or pass. If you hit, the dealer gives you one more card. If this card causes you to go over 21, you bust and your money goes to the winner. You can keep on 'hitting' until you bust. If you pass, you stay with the cards you have until everyone passes. The winner is the one that gets the value closest to 21.")
  rules=input("Do you know how to play?")
  rules=rules.lower()
while rules != "y" or rules != "yes":
  if rules=="y" or rules=="yes":
    print ("Ok")
    players=int(input("How many players are playing?"))
    for i in range(players):
      Player1="No"
      x=len(cards)
      hit10=random.randint(1,x-1)
      hit1=cards[hit10]
      cards.remove(hit1)
      x=len(cards)
      hit10=random.randint(1,x-1)
      hit2=cards[hit10]
      cards.remove(hit1)
      total=hit1+hit2
      print (hit1)
      print (hit2)
      while Player1!="pass":
        Player1=input("Would you like to hit or pass?")
        if Player1=="hit":
          x=len(cards)
          hit10=random.randint(1,x-1)
          hit3=cards[hit10]
          cards.remove(hit3)
          total+=hit3
          print (hit3)
          if total > 21:
            print ("You BUST! HAHA you lose.")
            Player1="pass"
            scores.append(("Player " + str(i+1) +  " busted"))
        elif Player1=="pass":
          hit3=0
          print ("Your total is", total)
          print ("You are", 21-total, "away from BlackJack")
          scores.append(("Player " + str(i+1) +  " was " + str(totalc-total) + " away from the house"))
      time.sleep (4)
      for x in range (100):
        print ()
        x+=1
      if i+1==players:
        print (scores)
  else:
    print ("Not a valid answer. Please try again.")