Problem with "while" & "break" in rock, paper, scissor program
Hi everybody - I'm trying to write a simple code where user will be allowed to make a string input. If they input rock, paper, or scissor, the program will move to the next step of having the computer choose rock, paper, or scissor. I made two lists: "win" & "lose", comparing what the user chose vs what the computer chose. Then depending of what the user chose & what the computer chose, the print-out should be "You win!" "You lose!" Or "It's a tie!" The actual output is always "It's a tie", no matter if user vs computer choice was in the win list, in the lose list, or in neither list. I'm also not sure of how to use the break function. NOTE: I used "while" instead of "if" in because I'd like to eventually carry this over so that the program runs three times instead of just once, each time comparing user input to the computer's random choice. Also, if there is any way to streamline my code, I'd love to hear it. Anyway, here's my code: ------ #play rock paper scissor against the computer #Choose rock, paper, scissor import random user = input() user = user.lower() print("User chooses: " + user) rps = ["rock", "paper", "scissor"] if user == "rock": user = rps[0] elif user == "paper": user = rps[1] elif user == "scissor": user = rps[2] elif user != rps[0] or user != rps[1] or user != rps[2]: print("You must input rock, paper, or scissor. All other entries are invalid.") while user == rps[0] or user == rps[1] or user == rps[2]: computer = random.choice(rps) print("Computer chooses: " +computer) win = [(rps[0] and computer[2]) or (rps[1] and computer[0]) or (rps[2] and computer[1])] lose = [(rps[0] and computer[1]) or (rps[1] and computer[2]) or (rps[2] and computer[0])] if win is True: print("You win!") elif lose is True: print("You lose!") else: print("It's a tie!") break