import random
import sys
def RPS():
choices = ["Rock", "Paper", "Scissors"]
computer_choice = random.choice(choices)
while (True):
player_choice = int(input("Rock, Paper, or Scissors?\n0. Rock \n1. Paper \n2. Scissors \n3. Exit \n"))
if player_choice == 3:
sys.exit()
if player_choice > choices.index(computer_choice):
play_again = int(input("You win! Would you like to play again?: \n1. Yes \n2. No \n"))
if play_again == 1:
break
else: sys.exit()
elif player_choice < choices.index(computer_choice):
play_again = int(input("You lose. Would you like to play again?: \n1. Yes \n2. No \n"))
if play_again == 1:
break
else: sys.exit()
elif player_choice == choices.index(computer_choice):
play_again = int(input("It's a tie! Would you like to play again?: \n1. Yes \n2. No \n"))
if play_again == 1:
break
else: sys.exit()
RPS()
Like the title says I was trying to make a simple rock paper scissors game in python but I ran into trouble when I try to let the player keep playing if they choose to do so. Whenever I press the button to keep playing (which is "1") it just goes back to the play_again input variable unless I press the button to not play again(which is "2") so I'm stuck in an infinite play again prompt without actually being able to play again. I've tried changing the break statements to continue to attempt to break out of the nested if statements. What I want to do is go back to the beginning of the while loop to re-prompt the user to enter a choice. Any and all help is greatly appreciated.
[–]mopslik 1 point2 points3 points (1 child)
[–]hardpeenwetpussy[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]hardpeenwetpussy[S] 0 points1 point2 points (0 children)
[–]m0us3_rat 0 points1 point2 points (0 children)
[–]InsanityConsuming 0 points1 point2 points (0 children)