fork(3) download
  1. import random as r
  2.  
  3. #the possible moves in rock paper scissors
  4. RPS = ["ROCK", "PAPER", "SCISSORS"]
  5.  
  6. def main():
  7. comp = computerMove()
  8. player = playerMove()
  9. winner, tie = calcWinner(comp, player)
  10. dispWinner(winner, tie)
  11.  
  12. #the move made by the computer
  13. def computerMove():
  14. return "ROCK"
  15.  
  16. #move made by the user
  17. def playerMove():
  18. player = ""
  19. while not player in RPS:
  20. player = input("Choose your weapon(rock, paper, or scissors: ").upper()
  21. ## print(player)
  22. return player
  23.  
  24. #determining a winner
  25. def calcWinner(comp, player):
  26. print("The computer chooses {0}.".format(comp))
  27. winner = None
  28. tie = False
  29.  
  30. ## if theres a tie
  31. if player == comp:
  32. print("No winner.... Restarting....\n")
  33. main()
  34. tie = True
  35.  
  36. ## if the user wins
  37. elif ((comp == "ROCK") and (player == "PAPER")) or ((comp=="PAPER") and (player == "SCISSORS")) or ((comp=="SCISSORS") and (player == "ROCK")):
  38. winner = True
  39. ## if computer won
  40. else:
  41. winner = False
  42.  
  43. return winner, tie
  44.  
  45. def dispWinner(winner, tie):
  46. if tie == True:
  47. print("TIE!!!!")
  48. elif winner == True:
  49. print("You beat the computer!")
  50. elif winner == False:
  51. print("The computer beat you!")
  52.  
  53.  
  54. main()
  55.  
Runtime error #stdin #stdout #stderr 0.02s 36952KB
stdin
ROCK
stdout
Choose your weapon(rock, paper, or scissors: The computer chooses ROCK.
No winner.... Restarting....

Choose your weapon(rock, paper, or scissors: 
stderr
Traceback (most recent call last):
  File "./prog.py", line 54, in <module>
  File "./prog.py", line 9, in main
  File "./prog.py", line 33, in calcWinner
  File "./prog.py", line 8, in main
  File "./prog.py", line 20, in playerMove
EOFError: EOF when reading a line