Advertisement
Guest User

rps

a guest
Oct 14th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import random
  2.  
  3. def rps(player_choice):
  4.     '''Basic rock paper scissors game
  5.    returns a list a boolean to see if winning as first list element
  6.    and the bot choice as second arguement'''
  7.     choices = ["rock", "paper", "scissors"]
  8.     player_wins = False
  9.     player_choice = player_choice.lower()
  10.     if player_choice not in choices:
  11.         return [False, ""]
  12.     bot_choice = random.choice(choices)
  13.     if bot_choice == player_choice:
  14.         player_wins = False
  15.     elif bot_choice == "rock" and player_choice == "scissors":
  16.         player_wins = False
  17.     elif bot_choice == "rock" and player_choice == "paper":
  18.         player_wins = True
  19.     elif bot_choice == "paper" and player_choice == "rock":
  20.         players_wins = False
  21.     elif bot_choice == "paper" and player_choice == "scissors":
  22.         player_wins = True
  23.     elif bot_choice == "scissors" and player_choice == "rock":
  24.         player_wins = True
  25.     else:
  26.         player_wins = False
  27.     return [player_wins, bot_choice]
  28.  
  29. def main():
  30.     running = True
  31.     while running:
  32.         game = rps(raw_input("rock paper scissors > "))
  33.         if game[0]:
  34.             print("You won the bot choose %s" % game[1])
  35.         else:
  36.             print("You lose the bot choose %s" % game[1])
  37.         if raw_input("Would you like to play again? ").lower() not in "okayes":
  38.             running = False
  39.  
  40. if __name__ == "__main__":
  41.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement