furas

Python - cards (reddit/r/learnpython)

Aug 28th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. #
  2. # https://www.reddit.com/r/learnpython/comments/4zyg0h/encountering_a_problem_with_defining_a_variable/
  3. #
  4. # http://pastebin.com/0RvD5JJ3
  5. #
  6.  
  7. dealer = input("Input a number for the dealer  ")
  8. player = input("input a score for the player  ")
  9.  
  10. print "The dealer's score is", dealer, "and your score is", player, "."
  11.  
  12. if dealer > 7:
  13.     print "The dealer has a natural!"
  14. elif dealer > 5:
  15.     print "The dealer does not deal himself a new card!"
  16. else: # now it has to be `dealer <= 5` so you don't need `elif/if`
  17.     #deal the dealer a third card
  18.     print "The dealer deals himself a third card!"
  19.     third_card = input("input the dealer's third card: ")
  20.     dealer = dealer + third_card
  21.     dealer = dealer % 10
  22.     # or in one line
  23.     # dealer = (dealer + third_card) % 10
  24.  
  25. if player > 7:
  26.     print "You have a natural!"
  27. elif player > 5:
  28.     print "You do not get dealt a third card!"
  29. else: # now it has to be `player <= 5` so you don't need `elif/if`
  30.     #deal the player a third card
  31.     third_card = input("input the player's third card: ")
  32.     player = player + third_card
  33.     player = player % 10
  34.     print "You have been dealt a third card! Your card is", third_card, "! Your total value is now", player, "!"
  35.  
  36. if player > dealer:
  37.     print "You win! You have a final score of", player, "and the dealer had a score of", dealer, "!"
  38. elif player < dealer:
  39.     print "The dealer wins! He had a score of", dealer, "and you had a score of", player, "!"
  40. else: # now it has to be `player == dealer` so you don't need `elif/if`
  41.     print "It is a draw! Both players have a final value of", dealer, "!"
Add Comment
Please, Sign In to add comment