ismaelvc

RPS.py

Apr 20th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/python
  2. import random
  3. import sys
  4.  
  5. def game():
  6.     options = ["rock","paper","scissors"]
  7.     computer_choice = random.choice(options)
  8.     player_choice = (raw_input('\nPlease enter your choice '
  9.                                'of rock, paper, '
  10.                                'or scissors to play:\n>> ')).lower()
  11.  
  12.     if player_choice ==  computer_choice:
  13.         print ("\nIt is a tie!!")
  14.  
  15.     elif player_choice == "rock" and computer_choice == "paper":
  16.         print ("\npaper beats rock -- You lost!!")
  17.     elif player_choice == "paper" and computer_choice == "scissors":
  18.         print ("\nscissors beats paper -- You lost!!")
  19.     elif player_choice == "scissors" and computer_choice == "rock":
  20.         print ("\nrock beats scissors -- You lost!!")
  21.  
  22.     elif player_choice == "rock" and computer_choice == "scissors":
  23.         print ("\nrock beats scissors -- You win!!")
  24.     elif player_choice == "paper" and computer_choice == "rock":
  25.         print ("\npaper beats rock -- You win!!")
  26.     elif player_choice == "scissors" and computer_choice == "paper":
  27.         print ("\nscissors beats paper -- You win!!")  
  28.      
  29.     else:
  30.         print('\nThats not a valid option.')
  31.         game()
  32.  
  33.     def again():
  34.         choice = raw_input("\nWould you like another game?\n>> ").lower()
  35.         if choice in ["yes", 'y']:
  36.             game()
  37.         elif choice in ["no", 'n']:
  38.             sys.exit()
  39.         else:
  40.             again()
  41.  
  42.     again()
  43.  
  44. game()
Advertisement
Add Comment
Please, Sign In to add comment