bwukki

Untitled

Oct 31st, 2017
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. from random import *
  2. #Start of function "rps" (rock paper scissors)
  3. def rps():
  4.     #chooses a random number between 1 and 3, uses that to determine rock/paper/scissor choice
  5.     x = randint(1,3)
  6.     if x == 1:
  7.         x = "rock"
  8.     if x == 2:
  9.         x = "paper"
  10.     else:
  11.         x = "scissors"
  12.        
  13.     y = input("Rock, paper, or scissors? ")
  14.     #checks to see if the input was valid, if it's not you get a message and it asks for a new input by calling the whole function again.
  15.     if (y != "Rock") and (y != "rock") and (y != "Paper") and (y != "paper") and (y != "Scissors") and (y != "scissors") :
  16.         print("Invalid input. Please choose rock, paper, or scissors.")
  17.         rps()
  18.     print("I'm going to choose...",x)
  19.  
  20.     #checks for a tie
  21.     if x == y:
  22.         print("Tie!")
  23.     if x == "rock":
  24.         x = "Rock"
  25.     if x == "paper":
  26.         x = "Paper"
  27.     else:
  28.         x = "Scissors"
  29.     if x == y:
  30.         print("Tie!")
  31.  
  32.     #checks other win conditions    
  33.     if x == "Rock":
  34.         if (y == "Scissors") or (y == "scissors"):
  35.             print("You lose!")
  36.         if (y == "Paper") or (y == "paper"):
  37.             print ("You win!")
  38.            
  39.     if x == "Paper":
  40.         if (y == "Rock") or (y == "rock"):
  41.             print("You lose!")
  42.         if (y == "Scissors") or (y == "scissors"):
  43.             print ("You win!")
  44.            
  45.     if x == "Scissors":
  46.         if (y == "Paper") or (y == "paper"):
  47.             print("You lose!")
  48.         if (y == "Rock") or (y == "rock"):
  49.             print ("You win!")
  50.     rps()
  51.     #calls itself to loop endlessly
  52.     return;
  53. #end of function rps
  54. rps()
Advertisement
Add Comment
Please, Sign In to add comment