Vo1d
Vo1d

Reputation: 15

Simply Python Rock ,paper,scissors game help needed

I'm needing help to finish this code, all seems to work as it should apart from the results, for example I will go through the game, once both players have selected either 'r', 's' or 'p' it will end the game with "Thanks for Playing Rock, Paper, Scissors" and skip the results on who won. here is the code, Thonny is telling me it all looks good and is working correctly which it isn't.

here is the code so far:

print("Welcome to Rock, Paper, Scissors!")
print("Let's 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. " )
choice2 = input(name2 + ": enter 'r' for rock, 'p' for paper, 's' for scissors: ")


if name1 == name2:
    print("Both players selected {'r', 's', 'p'}. It's a tie!")
elif name1 == "r":
    if name2 == "s":
        print("Rock smashes scissors! You win!")
    else:
        print("Paper covers rock! You lose.")
elif name1 == "p":
    if name2 == "r":
        print("Paper covers rock! You win!")
    else:
        print("Scissors cuts paper! You lose.")
elif name1 == "s":
    if name2 == "p":
        print("Scissors cuts paper! You win!")
    else:
        print("Rock smashes scissors! You lose.")


print("Thanks for Playing Rock, Paper, Scissors")

Upvotes: 0

Views: 279

Answers (3)

qwerteee
qwerteee

Reputation: 307

As @locke said, you were using name1 and name2 in the inputs for r, p, and s instead of choice1 and choice2.

You were also printing {'r', 's', 'p'} instead of the one that was chosen by both players, so just replace that with choice1 or choice2.

print("Welcome to Rock, Paper, Scissors!")
print("Let's 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. " )
choice2 = input(name2 + ": enter 'r' for rock, 'p' for paper, 's' for scissors: ")


if choice1 == choice2:
    print("Both players selected " + choice1 + ". It's a tie!")
elif choice1 == "r":
    if choice2 == "s":
        print("Rock smashes scissors! You win!")
    else:
        print("Paper covers rock! You lose.")
elif choice1 == "p":
    if choice2 == "r":
        print("Paper covers rock! You win!")
    else:
        print("Scissors cuts paper! You lose.")
elif choice1 == "s":
    if choice2 == "p":
        print("Scissors cuts paper! You win!")
    else:
        print("Rock smashes scissors! You lose.")


print("Thanks for Playing Rock, Paper, Scissors")

Upvotes: 1

Mohamed Yahya
Mohamed Yahya

Reputation: 493

First of all you are working in the if-statements with the names, you should work with choices. and also you can replace the list in the first condition with the first choice.

Upvotes: 0

Locke
Locke

Reputation: 374

You're reading the input ('r', 'p', or 's') into choice1 and choice2, but then you're doing a bunch of conditionals using name1 and name2. You probably want those conditionals to be on choice1 and choice2.

As an aside, it would probably be a good idea to sanitize your input. Right now you aren't verifying that the user is inputting one of these letters - they could be inputting anything!

Upvotes: 0

Related Questions