So I'm trying to make a rock, paper, scissors game and I'm trying to make it so that if the user (or computer) either gets 3 points OR the user's (or computer's) score is greater by 2 (like a best 2 out of 3 game) then the user (or computer) wins. But I can't seem to get it to work. I just started learning Python and programming in general so I'd appreciate an explanation that's as simple as possible.
Here is the code that I tried:
def rpc_game_normal ():
rpc = ['r', 'p', 's']
computer_wins = 0
wins = 0
while True:
print(f"Me: {computer_wins} | You: {wins} ")
user = input('Your move human: ').lower()
computer = random.choice(rpc)
if user == computer:
wins += 0
computer_wins += 0
elif pattern(user, computer):
computer_wins += 1
else:
wins += 1
score(wins, computer_wins)
print(f"I chose {computer} and you chose {user}.")
def pattern(user, computer):
if (user == 'r' and computer == 's') or (user == 'p' and computer == 'r') or \
(user == 's' and computer == 'p'):
return True
def score(user, computer):
if computer + 2 > user:
return True
elif user + 2 > computer:
return True
elif user == 3:
print("You win!")
return True
else:
print("I win!")
return True
Me: 0 | You: 0 Your move human: r I chose s and you chose r. Me: 1 | You: 0 Your move human: s I chose s and you chose s.
This is the outcome of what I get. I just get this same loop repeated over and over again even if the criteria is met.