Rock, Paper Scissors game help

Hello, Ive been tasked to create a rock paper scissors game for school and am struggling to get the print function to display a loss for some. r = Rock and s = Scissors, when i try r and s it prints You win etc although s and r it prints nothing

Please help!!~!!

if choice1 == "r":
    if choice2 == "s":
        print("You win " +name1 + " Rock beats Scissors!")
    else:
        print("You lose " +name1 + " Rock beats Scissors!")

We’d need to see the complete code - the code above looks basicly
correct (although there are going to be many branches).

Your code tests the string “r” etc but you talk of “r=Rock” above. Is
“r” actually in choice1? Before your if-statements, put these prints:

print("choice1 =", repr(choice1))
print("choice2 =", repr(choice2))

That will show you exactly what is actually in choice1 and choice2 - I
would guess they do not contain the exact strings you’re testing.

The first step to debugging issues like this is often to print out the
values involved - if they’re not what you thought they were then all the
examination of the programme logic in the world may not help, as your
ideas of what will happen are based on circumstances different from
reality.

Cheers,
Cameron Simpson cs@cskk.id.au

No worries and thanks for the response! Here is the full code, Ive just been experimenting with different ways of trying to get it to work as you can see, indenting randomly so its not 100% atm

print("Welcome to Rock ,Paper, Scissors!")
print("Lets Begin ...")
name1 = input("Player 1:What's your name?")
name2 = input("Player 2:What's your name?")

print("Hello " +name1 + " and " +name2)
print(name2 + ": Close your eyes!")

choice1 = input(name1 + ": enter 'r' for rock, 'p' for paper, and 's' for scissors: ")
print("Great choice! Now - cover your answer and ask " +name2 + " to choose. \n\n\n")
choice2 = input(name2 + ": enter 'r' for rock, 'p' for paper, and 's' for scissors: ")

if choice1 == choice2:
    print("Both players have chosen the same answer, it is a tie!")

if choice1 == "r":
    if choice2 == "p":
        print("You win " +name2 + " Paper beats Rock!")
else:
    if choice1 == "p":
        print("You lose " +name1 + " Paper beats Rock!")
    if choice1 == "r":
        if choice2 == "s":
            print("You win " +name1 + " Rock beats Scissors!")
    else:
        print("You lose " +name1 + " Rock beats Scissors!")
        
            

    if choice1 == "s":
        if choice2 == "p":
            print("You win " +name1 + " Scissors beats Paper!")
    else:
        if choice1 == "p":
            if choice2 == "s":
                print("You lose " +name1 + " Scissors beats Paper!")

No worries and thanks for the response! Here is the full code, Ive just
been experimenting with different ways of trying to get it to work as
you can see, indenting randomly so its not 100% atm

You need to print(repr(choice1)) and also choice2 to check that they are
what you expect.

if choice1 == choice2:
print(“Both players have chosen the same answer, it is a tie!”)

You need an else: under here to prevent the rest of the comparisons from
running; indent them under it.

if choice1 == “r”:
if choice2 == “p”:
print(“You win " +name2 + " Paper beats Rock!”)

You need and else for the !=“p” case. And so on in various combinations.
Even with just 3 variations you need about 6 branches to cover all the
combinations, after you’ve excluded the choice1==choice2 case. Imagine
how it would be with more choices, or more players.

Anyway, you need a print for both the true and false alternatives of
every if-statement to see where things are working, or not working.

Cheers,
Cameron Simpson cs@cskk.id.au

I would suggest to put your efford in algorithm. Define it in natural language and then translate it into Python.

It boils down to how to determine result. Basically there can be two outcomes: (1) draw or (2) either side wins.

Draw is simple - if choices are equal. If it’s not a draw then to determine winner there are actually only three combinations (first choice wins): Rock-Scissors, Paper-Rock, Scissors-Paper. If it’s not draw and not first choice wins then second choice is winner.

Based on that it is possible to write much simpler code:

first_wins = [('Rock', 'Scissors'), ('Paper', 'Rock'), ('Scissors', 'Paper')]

if first_choice == second_choice:
    # draw
elif (first_choice, second_choice) in first_wins:
    # first_choice wins
else:
    # second_choice wins

There are other ways to determine a result but I think this is good for starters.

Cheers everyone for the replies and the problem is I have to use the ‘template’ code that I was given for the assessment, I’ve fixed some things up although I still don’t get a print output when I do p then s. Here is the updated code, only posted whats been updated.

if choice1 == choice2:
    print("Both players have chosen the same answer, it is a tie!")

#All possible answers:
else:
    if choice1 == "p":
        if choice2 == "r":
            print("You win " +name2 + " Paper beats Rock!")
    else:
        if choice1 == "r" and choice2 == "p":
            print("You lose " +name1 + " Paper beats Rock!")
        else:
            if choice1 == "r":
                if choice2 == "s":
                    print("You win " +name1 + " Rock beats Scissors!")
            else:
                if choice1 == "s" and choice2 == "r":
                    print("You lose " +name1 + " Rock beats Scissors!")
                else:
                    if choice1 == "s":
                        if choice2 == "p":
                            print("You win " +name1 + " Scissors beats Paper!")
                    else:
                        if choice1 == "p" and choice2 == "s":
                            print("You lose " +name1 + " Scissors beats Paper!")

Cheers everyone for the replies and the problem is I have to use the
‘template’ code that I was given for the assessment, I’ve fixed some
things up although I still don’t get a print output when I do p then s.
Here is the updated code, only posted whats been updated.
[…]
if choice1 == “p”:
if choice2 == “r”:
print(“You win " +name2 + " Paper beats Rock!”)
else:
if choice1 == “r” and choice2 == “p”:
print(“You lose " +name1 + " Paper beats Rock!”)
else:
if choice1 == “r”:
print(“You win " +name1 + " Rock beats Scissors!”)
[…]

Python has an “elif” shorthand for “else: if” which removes the
increasing indent you see above, like this:

if choice1 == "p":
    if choice2 == "r":
        print("You win " +name2 + " Paper beats Rock!")
elif choice1 == "r" and choice2 == "p":
    print("You lose " +name1 + " Paper beats Rock!")
elif choice1 == "r":
    print("You win " +name1 + " Rock beats Scissors!")

Handy for cascades like this.

Cheers,
Cameron Simpson cs@cskk.id.au