-1
from random import randint
import getpass
import time

t = ["ROCK", "PAPER", "SCISSORS"]

handle = int(input("How many players? (max = 2)\n"))
if handle < 2 :
    player = False
else: player = True

while player == True:
    player1 = ''
    player2 = ''
    print("Ready Player 1.")
    while player1 not in t:
        player1 = getpass.getpass("Rock, Paper, Scissors?\n")
        if player1.upper() in t:
            break
        else:
            print("Check your spelling.")
            continue
    print("Ready Player 2.")
    time.sleep(1)
    while player2 not in t:
        player2 = getpass.getpass("Rock, Paper, Scissors?\n")
        if player2.upper() in t :
            break
        else:
            print("Check your spelling.")
            continue
    if player1 == player2:
        print("Tie!")
    elif player1 == "Rock":
        if player2 == "Paper":
            print("You lose!", player2, "covers", player1)
        else:
            print("You win!", player1, "smashes", player2)
    elif player1 == "Paper":
        if player2 == "Scissors":
            print("You lose!", player2, "cut", player1)
        else:
            print("You win!", player1, "covers", player2)
    elif player1 == "Scissors":
        if player2 == "Rock":
            print("You lose!", player2, "smashes", player1)
        else:
            print("You win!", player1, "cut", player2)
    else:
        print("That's not a valid play. Check your spelling.")

    next1 = input("Care to play again, Player 1? yes/no\n")
    next2 = input("Care to play again, Player 2? yes/no\n")
    if next1.lower() == next2.lower() == "yes":
        player = True
        continue
    elif next1 != next2:
        player = False
        continue
    else: quit()

This is the (wordy) code for a rock paper scissor game that allows for 2 players to input choices. I'm having an issue at the PLAYER 2 segment. The issue is a bug when it comes down to player 2. Here is the scenario: "Ready Player 1" [player 1 input] (if not in t, it allows it to p1 to keep attempting) "Ready Player 2" [player 2 input]ISSUE:[if entered the wrong choice (GHOST?), then the choice "ROCK", the code works. If instead of "ROCK" you chose "PAPER" or "SCISSORS" the code skips all the following code (which decides who won the game.)

Caribou
  • 11
  • 1
  • You might want to use a [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) for that or look at [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Andreas Jul 25 '19 at 01:56

1 Answers1

1

You check if player1.upper() in t. But that would allow "ROCK", "Rock", or "rock" to break out of the loop. When you compare the two players, you only compare if they're exactly equal, but "ROCK" is not exactly equal to "Rock".

Your code only checks for "Rock", "Paper" and "Scissors" exactly after it gets input.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278