Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- #Start of function "rps" (rock paper scissors)
- def rps():
- #chooses a random number between 1 and 3, uses that to determine rock/paper/scissor choice
- x = randint(1,3)
- if x == 1:
- x = "rock"
- if x == 2:
- x = "paper"
- else:
- x = "scissors"
- y = input("Rock, paper, or scissors? ")
- #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.
- if (y != "Rock") and (y != "rock") and (y != "Paper") and (y != "paper") and (y != "Scissors") and (y != "scissors") :
- print("Invalid input. Please choose rock, paper, or scissors.")
- rps()
- print("I'm going to choose...",x)
- #checks for a tie
- if x == y:
- print("Tie!")
- if x == "rock":
- x = "Rock"
- if x == "paper":
- x = "Paper"
- else:
- x = "Scissors"
- if x == y:
- print("Tie!")
- #checks other win conditions
- if x == "Rock":
- if (y == "Scissors") or (y == "scissors"):
- print("You lose!")
- if (y == "Paper") or (y == "paper"):
- print ("You win!")
- if x == "Paper":
- if (y == "Rock") or (y == "rock"):
- print("You lose!")
- if (y == "Scissors") or (y == "scissors"):
- print ("You win!")
- if x == "Scissors":
- if (y == "Paper") or (y == "paper"):
- print("You lose!")
- if (y == "Rock") or (y == "rock"):
- print ("You win!")
- rps()
- #calls itself to loop endlessly
- return;
- #end of function rps
- rps()
Advertisement
Add Comment
Please, Sign In to add comment