Advertisement
towwey

Rock,Paper,Scissors Best two out of three.

Apr 30th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. #!/usr/bin/python
  2. from random import randint
  3.  
  4. #create a list of play options
  5. t = ["rock", "paper", "scissors"]
  6. comp_wins = 0
  7. player_wins = 0
  8.  
  9. while True:
  10.     player = input("Rock, paper, scissors? ")
  11.     computer = t[randint(0,2)]
  12.     if player == computer:
  13.         print("Computer chose: " + computer)
  14.         print("Tie!")
  15.     elif player == "rock":
  16.         if computer == "paper":
  17.             print("Computer chose: " + computer)
  18.             print("You lose!")
  19.             comp_wins += 1
  20.         else:
  21.             print("Computer chose: " + computer)
  22.             print("You win!")
  23.             player_wins += 1
  24.     elif player == "paper":
  25.         if computer == "scissors":
  26.             print("Computer chose: " + computer)
  27.             print("You lose")
  28.             comp_wins += 1
  29.         else:
  30.             print("Computer chose: " + computer)
  31.             print("You win!")
  32.             player_wins += 1
  33.     elif player == "scissors":
  34.         if computer == "rock":
  35.             print("Computer chose: " + computer)
  36.             print("You lose!")
  37.             comp_wins += 1
  38.         else:
  39.             print("Computer chose: " + computer)
  40.             print("You win!")
  41.             player_wins += 1
  42.     else:
  43.         print("Not a valid entry")
  44.        
  45.     if player_wins == 3:
  46.         print("You win the match")
  47.         break          
  48.     if comp_wins == 3:
  49.         print("The computer wins the match")
  50.         break
  51.     if player_wins == 2 and comp_wins == 0:
  52.         print("You win the match")
  53.         break          
  54.     if comp_wins == 2 and player_wins == 0:
  55.         print("The computer wins the match")
  56.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement