Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Helping someone on Reddit debug their program. THIS IS NOT MY WORK!
- """
- #!/usr/bin/env python3
- import random
- class RockPaperScissors():
- def __init__(self):
- self.FORMS = ("R", "P", "S")
- self.play_again = True
- def choose_form(self):
- print("Enter 'R', 'P', or 'S'\nfor rock, paper, or scissors.")
- hand = input().upper()
- print("The value of hand at line 14 is {}.".format(hand))
- return hand
- def decide(self, hands):
- for x in hands.keys():
- print("The value of x at line 19 is {}".format(x))
- for y in hands.keys():
- print("The value of y at line 21 is {}".format(y))
- if ((hands[x] == "R" and hands[y] == "S") or
- (hands[x] == "P" and hands[y] == "R") or
- (hands[x] == "S" and hands[y] == "P")):
- winner = x
- else:
- winner = None
- print("The value of winner at line 29 is {}".format(winner))
- return winner
- def play(self):
- hands = {}
- while self.play_again:
- print("=== Rock, Paper, Scissors ===\n")
- hands["Player"] = self.choose_form()
- hands["Computer"] = random.choice(self.FORMS)
- print("\nYou chose {}, the computer chose {}.".format(
- hands["Player"], hands["Computer"]
- ))
- winner = self.decide(hands)
- # this variable seems to be None every time
- if winner:
- print("The winner is:", winner)
- else:
- print("It's a tie!")
- self.play_again = True
- answer = input("Play again? (Y/N) ").upper()
- if answer == "Y":
- self.play_again = True
- else:
- self.play_again = False
- print("Thanks for playing!")
- def main():
- rps_game = RockPaperScissors()
- rps_game.play()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement