Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. """
  2. Rock, Paper, or Scissors project. The user can insert a choice, and, in return the compute will display a random choice.
  3. """
  4.  
  5. from random import randint
  6. from time import sleep
  7.  
  8. options = ["R", "P", "S"]
  9. LOSS_MESSAGE = "You lost!"
  10. WIN_MESSAGE = "Yay....You won!"
  11. def decide_winner(user_choice, computer_choice):
  12. print "You selected: %s" % user_choice # check
  13. sleep (1)
  14. print "computer selected: %s" % computer_choice # check
  15. sleep (1)
  16.  
  17. user_choice_index = options.index(user_choice)
  18. computer_choice_index = options.index(computer_choice)
  19. if user_choice_index == computer_choice_index:
  20. print "It is a tie!"
  21. elif user_choice_index == 0 and computer_choice_index==2:
  22. print WIN_MESSAGE
  23. elif user_choice_index == 1 and computer_choice_index==0:
  24. print WIN_MESSAGE
  25. elif user_choice_index == 2 and computer_choice_index==1:
  26. print WIN_MESSAGE
  27. elif user_choice_index > 2:
  28. print "Invalid choice"
  29. return #check
  30. else:
  31. print LOSS_MESSAGE
  32. def play_RPS():
  33. print "Rock, Paper, or Scissors?"
  34. user_choice = raw_input ("select R for Rock, P for Paper, or S for Scissors: ")
  35. spleep (1)
  36. user_choice = user_choice.upper()
  37. computer_choice = options[randint(0,len(options)-1)]
  38. decide_winner(user_choice, computer_choice)
  39. play_RPS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement