Advertisement
NightRaven97

Rock-Paper-Scissors in Python

Aug 1st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. #Rock Paper Scissors
  2. import random
  3. #1 corresponds to Rock, 2 corresponds to Paper, 3 corresponds to Scissors.
  4. choices=[1,2,3]
  5. player_pt=0
  6. bot_pt=0
  7. player_choice=0
  8. bot_choice=0
  9. #Function for initiating bot_choice and getting player_choice.
  10. def initialize():
  11.     global bot_choice
  12.     bot_choice=random.choice(choices)
  13.     print "\n1.Rock\n2.Paper\n3.Scissors"
  14.     global player_choice
  15.     player_choice=int(raw_input("Enter the number of your choice:"))
  16.     while player_choice not in range(1,4):
  17.         player_choice=raw_input("\nInvalid input!\nEnter the number alone.\n1.Rock\n2.Paper\n3.Scissors\nEnter your choice again:")
  18.  
  19. #Function for evaluation.
  20. def evaluate():
  21.     global player_pt
  22.     global bot_pt
  23.     if player_choice==bot_choice:
  24.         print "\nThat was a tie!\nLets try again! Bet I'll win this time!"
  25.     elif player_choice==1 and bot_choice==2:
  26.         bot_pt+=1
  27.         print "\nI beat you this time!I chose Paper!"
  28.         print player_name,":",player_pt,"\nBot:",bot_pt
  29.     elif player_choice==1 and bot_choice==3:
  30.         player_pt+=1
  31.         print "\nYou got lucky!You won this time!I chose Scissors!"
  32.         print player_name,":",player_pt,"\nBot:",bot_pt
  33.     elif player_choice==2 and bot_choice==1:
  34.         player_pt+=1
  35.         print "\nYou got lucky!You won this time!I chose Rock!"
  36.         print player_name,":",player_pt,"\nBot:",bot_pt
  37.     elif player_choice==2 and bot_choice==3:
  38.         bot_pt+=1
  39.         print "\nI beat you this time!I chose Scissors!"
  40.         print player_name,":",player_pt,"\nBot:",bot_pt
  41.     elif player_choice==3 and bot_choice==1:
  42.         bot_pt+=1
  43.         print "\nI beat you this time!I chose Rock!"
  44.         print player_name,":",player_pt,"\nBot:",bot_pt
  45.     elif player_choice==3 and bot_choice==2:
  46.         player_pt+=1
  47.         print "\nYou got lucky!You won this time!I chose Paper!"
  48.         print player_name,":",player_pt,"\nBot:",bot_pt
  49.  
  50. print "Hi there! I'm Rock-Paper-Scissors bot!"
  51. player_name=raw_input("What's your name?")
  52. print "Ready to play with me",player_name,"?! One who scores 10 points first wins!!"
  53. while player_pt<10 and bot_pt<10:
  54.     initialize()
  55.     evaluate()
  56. if player_pt==10:
  57.     print "\nKudos",player_name,"! You won!"
  58. elif bot_pt==10:
  59.     print "\nI won!Better luck next time",player_name,"!"  
  60. raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement