Guest User

Untitled

a guest
Jun 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. #This is a simple paper, rock, scissors game, where the players
  2. #enter one of those three options, and the program determines which is the
  3. #winner, with the rules of "paper beats scissors, scissors beats paper,
  4. #and paper beats rock".
  5. #THe following two lines sets the values of "value1" and "value2" to 0. These are the strings
  6. #that will allow us to compare the input from player one to player2
  7. value1=0
  8. value2=0
  9.  
  10. #this is the instruction that takes input from player 1 and translates it
  11. #to an integer value, which allows us to compare it to player 2 (I think the
  12. #previous 3 lines of code aren't necessary, but hey, they're in there.
  13. player1=raw_input("Player 1, enter 'rock' 'paper' or 'scissors': ")
  14. if player1 == "rock":
  15.     value1=3
  16. elif player1 == "scissors":
  17.     value1=2
  18. elif player1 == "paper":
  19.     value1=1
  20. #This tells the player if they didn't enter a valid option for their input
  21. else:
  22.     print "You didn't enter a valid object."
  23.  
  24. #This is the same as for player one, it just assigns the value of
  25. #rock, etc, to "value2"
  26. player2=raw_input("Player 2, enter 'rock' 'paper' or 'scissors': ")
  27. if player2 == "rock":
  28.     value2=3
  29. elif player2 == "scissors":
  30.     value2=2
  31. elif player2 == "paper":
  32.     value2=1
  33. else:
  34.     print "You didn't enter a valid object."
  35.  
  36. #next, we assign a function to compare value1 to value2 (I think
  37. #you really don't need this as a function, but i like functions.
  38. def testvalue(value1, value2):
  39.     if value1==3 and value2==1:
  40.         print "Player 2 wins."
  41.     elif value1==1 and value2==3:
  42.         print "Player 1 wins."
  43.     elif value1==value2:
  44.         print "Tie."
  45.     elif value1 > value2:
  46.         print "Player 1 wins."
  47.     elif value2 > value1:
  48.         print "Player 2 wins."
  49.  
  50. #then we run the function, with value1 and value2
  51. testvalue(value1, value2)
Add Comment
Please, Sign In to add comment