Advertisement
afeyajahin

RPS problem

Sep 15th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #main
  2. def playRPS(userChoice):
  3. compChoice= generateCompChoice()
  4. determineWinner(compChoice,userChoice)
  5. printOutcome(userChoice, compChoice, determineWinner)
  6.  
  7. import random
  8. def generateCompChoice():
  9. # input nothing
  10. number=random.randint(0,2)
  11. if number ==0:
  12. return "rock"
  13. elif number ==1:
  14. return "paper"
  15. else:
  16. return "scissors"
  17. # generates a random number (0,1,2)
  18. # return number
  19.  
  20. # Determine the winner
  21. # Input compChoice, userChoice
  22. def determineWinner(compChoice, userChoice):
  23. if compChoice=="rock" and userChoice=="r" or compChoice == "paper" and userChoice == "p" or compChoice == "scissors" and userChoice== "s":
  24. return "tied"
  25. elif compChoice=="rock" and userChoice=="p" or compChoice=="paper" and userChoice=="s" or compChoice == "scissors" and userChoice == "r":
  26. return "won"
  27. else:
  28. return "lost"
  29. def userInput(userChoice):
  30. if userChoice=="r":
  31. return "rock"
  32. elif userChoice=="p":
  33. return "paper"
  34. else:
  35. return "scissors"
  36. def printOutcome(userChoice, compChoice, determineWinner):
  37. print("You chose"+ userInput(userChoice)+ "and the computer chose"+ generateCompChoice()+", so you"+determineWinner(compChoice, userChoice))
  38.  
  39. print("welcome to rock, paper, scissors!")
  40. userChoice = input("choose your item [r/p/s]:")
  41. playRPS(userChoice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement