Jun-19-2021, 03:33 AM
For a homework assignment, I'm making a rock paper scissors bot that plays against you. However it has one particular bug. Here is the code in its entirety.
import random def RPS(): R="rock" P="paper" S="scissors" player_choice=input("What do you want to play? R/P/S") throw_choice=[R,P,S] computer_choice=random.choice(throw_choice) if player_choice=="R": print("You played rock, and the computer played "+computer_choice+".") elif player_choice=="P": print("You played paper, and the computer played "+computer_choice+".") elif player_choice=="S": print("You played scissors, and the computer played "+computer_choice+".") if computer_choice==player_choice: return "T" elif computer_choice==R: if player_choice=="P": return "W" elif player_choice=="S": return "L" elif computer_choice==P: if player_choice=="R": return "L" elif player_choice=="S": return "W" elif computer_choice==S: if player_choice=="R": return "W" if player_choice=="P": return "L" def play_RPS(): continue_playing="Yes" win_count=0 loss_count=0 tie_count=0 while (continue_playing=="Yes"): continue_playing=input("Do you want to continue playing? Yes/No ") if continue_playing=="Yes": RPS() if RPS()=="W": print("You won!") win_count=win_count+1 elif RPS()=="L": print("You lost...") loss_count=loss_count+1 elif RPS()=="T": print("You tied.") tie_count=tie_count+1 print("Here are the results!") print("Wins:"+str(win_count)) print("Losses:"+str(loss_count)) print("Ties:"+str(tie_count)) play_RPS()What it is supposed to do is first ask you if you want to continue playing the game, and then it asks you what you want to play, and then the computer randomly picks what to play. It then is supposed to reveal the result of the round before asking you if you want to continue playing again, and so on. However, depending on what I pick, the segment where the computer asks for the player's throw loops a different number of times depending on what I pick. I have no idea what is causing this bug and I would very much like advice. Also for some reason the indents don't show up on the post so just pretend like they're there.