Advertisement
Tamas4

Paper, Scissors, Rock

Nov 15th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. """The program should do the following:
  2.  
  3. 1. Prompt the user to select either Rock, Paper, or Scissors.
  4. 2. Instruct the computer to randomly select either Rock, Paper, or Scissors.
  5. 3. Compare the user's choice and the computer's choice.
  6. 4. Determine a winner (the user or the computer).
  7. 5. Inform the user who the winner is."""
  8.  
  9. from random import randint
  10.  
  11. options = ["ROCK", "PAPER", "SCISSORS"]
  12. message = {"tie" : "Yawn it's a tie!", "won" : "Yay you won!", "lost" : "Aww you lost!"}
  13.  
  14. def decide_winner(user_choice,computer_choice):
  15.   print "You selected: %s" % user_choice
  16.   print "Computer selected: %s" % computer_choice
  17.   if user_choice == computer_choice:
  18.     print message["tie"]
  19.   elif user_choice == options[0] and computer_choice == options[2]:
  20.     print message["won"]
  21.   elif user_choice == options[1] and computer_choice == options[0]:
  22.     print message["won"]
  23.   elif user_choice == options[2] and computer_choice == options[1]:
  24.     print message["won"]
  25.   else:
  26.     print message["lost"]
  27.  
  28. def play_RPS():
  29.   print "Rock, Paper, or Scissors?"
  30.   user_choice = raw_input("Enter Rock, Paper, or Scissors: ")
  31.   user_choice = user_choice.upper()
  32.   computer_choice = options[randint(0, 2)]
  33.   decide_winner(user_choice, computer_choice)
  34.  
  35. play_RPS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement