Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def draw():
- x=random.randint(1,13)
- return x
- def value(x):
- if x==1:
- return 11
- if x>10:
- return 10
- return x
- def count(T):
- s=0
- for k in range(0,len(T)):
- s=s+value(T[k])
- for k in range(0,len(T)):
- while s>21:
- if T[k]==1:
- s=s-10
- return s
- player=[draw(),draw()]
- dealer=[draw(),draw()]
- print("dealer hand is: ",dealer[0])
- while count(player)<21:
- print ("your hand is: ",player," and your count is: ",count(player))
- dec=input("draw a card ?(y/n)")
- if dec=="y":
- player.append(draw())
- if dec=="n":
- break
- if count(player)>21:
- print("you lost")
- if count(player)>21:
- print("you lost")
- else:
- while count(dealer)<16:
- dealer.append(draw())
- print("dealer hand is: ",dealer," and count is",count(dealer))
- if count(dealer)>21:
- print("you win")
- elif count(dealer)<count(player):
- print ("you win")
- else:
- print("you lost")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement