Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #main
- def playRPS(userChoice):
- compChoice= generateCompChoice()
- determineWinner(compChoice,userChoice)
- printOutcome(userChoice, compChoice, determineWinner)
- import random
- def generateCompChoice():
- # input nothing
- number=random.randint(0,2)
- if number ==0:
- return "rock"
- elif number ==1:
- return "paper"
- else:
- return "scissors"
- # generates a random number (0,1,2)
- # return number
- # Determine the winner
- # Input compChoice, userChoice
- def determineWinner(compChoice, userChoice):
- if compChoice=="rock" and userChoice=="r" or compChoice == "paper" and userChoice == "p" or compChoice == "scissors" and userChoice== "s":
- return "tied"
- elif compChoice=="rock" and userChoice=="p" or compChoice=="paper" and userChoice=="s" or compChoice == "scissors" and userChoice == "r":
- return "won"
- else:
- return "lost"
- def userInput(userChoice):
- if userChoice=="r":
- return "rock"
- elif userChoice=="p":
- return "paper"
- else:
- return "scissors"
- def printOutcome(userChoice, compChoice, determineWinner):
- print("You chose"+ userInput(userChoice)+ "and the computer chose"+ generateCompChoice()+", so you"+determineWinner(compChoice, userChoice))
- print("welcome to rock, paper, scissors!")
- userChoice = input("choose your item [r/p/s]:")
- playRPS(userChoice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement