Advertisement
Guest User

blackjack

a guest
Feb 28th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import random
  2. def draw():
  3. x=random.randint(1,13)
  4. return x
  5. def value(x):
  6. if x==1:
  7. return 11
  8. if x>10:
  9. return 10
  10. return x
  11. def count(T):
  12. s=0
  13. for k in range(0,len(T)):
  14. s=s+value(T[k])
  15. for k in range(0,len(T)):
  16. while s>21:
  17. if T[k]==1:
  18. s=s-10
  19. return s
  20. player=[draw(),draw()]
  21. dealer=[draw(),draw()]
  22. print("dealer hand is: ",dealer[0])
  23. while count(player)<21:
  24. print ("your hand is: ",player," and your count is: ",count(player))
  25. dec=input("draw a card ?(y/n)")
  26. if dec=="y":
  27. player.append(draw())
  28. if dec=="n":
  29. break
  30. if count(player)>21:
  31. print("you lost")
  32. if count(player)>21:
  33. print("you lost")
  34. else:
  35. while count(dealer)<16:
  36. dealer.append(draw())
  37. print("dealer hand is: ",dealer," and count is",count(dealer))
  38. if count(dealer)>21:
  39. print("you win")
  40. elif count(dealer)<count(player):
  41. print ("you win")
  42. else:
  43. print("you lost")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement