I'm trying to make a rock paper scissors game with rounds. I'm using a while loop but it doesn't go back to the beginning. I've tried declaring the variables inside of the while, outside, and many other things, but it just doesn't work. I'll leave the code here. Thanks for the help!
import random
computer_win = 0
user_win = 0
jugadas = 0
def play(computer_win, user_win, jugadas):
while (jugadas < 3):
user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors: ")
computer = random.choice(['r','p','s'])
if user == computer:
jugadas = jugadas + 1
return( f'It\'s a tie. Round {jugadas}/3')
if is_win(user, computer):
user_win +=1
jugadas = jugadas + 1
return( f'You won! Round {jugadas}/3')
else:
computer_win +=1
jugadas = jugadas + 1
return( f'You lost! Round {jugadas}/3')
if computer_win >2 or user_win>2:
if computer_win > user_win:
"The computer won"
elif user_win > computer_win:
return "You won!"
else:
return "It's a tie ...."
def is_win(player, opponent):
if(player == 'r' and opponent == 's') or (player =='s' and opponent =='p') \
or (player =='p' and opponent == 'r'):
return True
print(play(computer_win, user_win, jugadas))