Advertisement
MickeyLater

helping_with_rps

Feb 13th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. """Helping someone on Reddit debug their program. THIS IS NOT MY WORK!
  2. """
  3.  
  4. #!/usr/bin/env python3
  5.  
  6. import random
  7.  
  8.  
  9. class RockPaperScissors():
  10.  
  11. def __init__(self):
  12. self.FORMS = ("R", "P", "S")
  13. self.play_again = True
  14.  
  15. def choose_form(self):
  16. print("Enter 'R', 'P', or 'S'\nfor rock, paper, or scissors.")
  17. hand = input().upper()
  18. print("The value of hand at line 14 is {}.".format(hand))
  19. return hand
  20.  
  21. def decide(self, hands):
  22. for x in hands.keys():
  23. print("The value of x at line 19 is {}".format(x))
  24. for y in hands.keys():
  25. print("The value of y at line 21 is {}".format(y))
  26. if ((hands[x] == "R" and hands[y] == "S") or
  27. (hands[x] == "P" and hands[y] == "R") or
  28. (hands[x] == "S" and hands[y] == "P")):
  29. winner = x
  30. else:
  31. winner = None
  32. print("The value of winner at line 29 is {}".format(winner))
  33. return winner
  34.  
  35. def play(self):
  36. hands = {}
  37.  
  38. while self.play_again:
  39.  
  40. print("=== Rock, Paper, Scissors ===\n")
  41.  
  42. hands["Player"] = self.choose_form()
  43. hands["Computer"] = random.choice(self.FORMS)
  44.  
  45. print("\nYou chose {}, the computer chose {}.".format(
  46. hands["Player"], hands["Computer"]
  47. ))
  48.  
  49. winner = self.decide(hands)
  50. # this variable seems to be None every time
  51.  
  52. if winner:
  53. print("The winner is:", winner)
  54. else:
  55. print("It's a tie!")
  56. self.play_again = True
  57.  
  58. answer = input("Play again? (Y/N) ").upper()
  59. if answer == "Y":
  60. self.play_again = True
  61. else:
  62. self.play_again = False
  63.  
  64. print("Thanks for playing!")
  65.  
  66.  
  67. def main():
  68. rps_game = RockPaperScissors()
  69. rps_game.play()
  70.  
  71. if __name__ == "__main__":
  72. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement