Omar
Omar

Reputation: 15

Python 3.X Rock Paper Scissors Lizard Spock issue

Hello i am new to coding but i have been stuck on a code for very long and can't seem to find the answer here on stackoverflow.

Whatever i do the answer ends up with the first print of Player 1 wins: Player One wins, Rock beats Scissors.

player1 = input("Player One do you want Rock, Paper, Scissors, Lizard or Spock?")
player2 = input("Player Two do you want Rock, Paper, Scissors, Lizard or Spock?")
print(player1)
print(player2)

rock = 1
paper = 2
scissors = 3
lizard = 4
spock = 5

#Tie

if (player1 == player2):
print("It's a tie.")

#Player 1 wins

elif (player1 == 1, player2 == 3):
    print("Player One wins, Rock beats Scissors.")
elif (player1 == 1, player2 == 4):
    print("Player One wins, Rock beats Lizard.")
elif (player1 == 2, player2 == 1):
    print("Player One wins, Paper beats Rock.")
elif (player1 == 2, player2 == 5):
    print("Player One wins, Paper beats Spock.")
elif (player1 == 3, player2 == 2):
    print("Player One wins, Scissors beats Paper.")
elif (player1 == 3, player2 == 4):
    print("Player One wins, Scissors beats Lizard.")
elif (player1 == 4, player2 == 2):
    print("Player One wins, Lizard beats Paper.")
elif (player1 == 4, player2 == 5):
    print("Player One wins, Lizard beats Spock.")
elif (player1 == 5, player2 == 3):
    print("Player One wins, Spock beats Scissors.")
elif (player1 == 5 , player2 == 1):
    print("Player One wins, Spock beats Rock.")

#Player 2 wins       

elif (player2 == 1, player1 == 3):
    print("Player Two wins, Rock beats Scissors.")
elif (player2 == 1, player1 == 4):
    print("Player Two wins, Rock beats Lizard.")
elif (player2 == 2, player1 == 1):
    print("Player Two wins, Paper beats Rock.")
elif (player2 == 2, player1 == 5):
    print("Player Two wins, Paper beats Spock.")
elif (player2 == 3, player1 == 2):
    print("Player Two wins, Scissors beats Paper.")
elif (player2 == 3, player1 == 4):
    print("Player Two wins, Scissors beats Lizard.")
elif (player2 == 4, player1 == 2):
    print("Player Two wins, Lizard beats Paper.")
elif (player2 == 4, player1 == 5):
    print("Player Two wins, Lizard beats Spock.")
elif (player2 == 5, player1 == 3):
    print("Player Two wins, Spock beats Scissors.")
elif (player2 == 5 , player1 == 1):
    print("Player Two wins, Spock beats Rock.")

Upvotes: 0

Views: 481

Answers (2)

MooingRawr
MooingRawr

Reputation: 4981

While TigerHawk covered your condiction, you also have to cast your inputs to ints.

player1 = int(player1)
player2 = int(player2)

Right now you are comparing a str (your input) to an int (player == 1). Which won't yield what you want.

player1 == 1      #fails right now since it's like asking "1" == 1 which fails.
int(player1) == 1 # passes since it's asking 1 == 1. 

Also your print("It's a tie.") is indented wrong.

Upvotes: 0

TigerhawkT3
TigerhawkT3

Reputation: 49310

You are not properly constructing your conditions.

elif (player1 == 1, player2 == 3)

This creates a tuple and then checks it for truthiness, which always succeeds, because that tuple is not empty. You need to use the logical operator and:

elif player1 == 1 and player2 == 3

This will check whether both of those conditions are true. Do this for all similar instances in your code.

Additionally, it's unclear what you are expecting from the user here:

player1 = input("Player One do you want Rock, Paper, Scissors, Lizard or Spock?")
player2 = input("Player Two do you want Rock, Paper, Scissors, Lizard or Spock?")
print(player1)
print(player2)

rock = 1
paper = 2
scissors = 3
lizard = 4
spock = 5

It looks like the user is supposed to enter something like Rock, and then you expect the rock = 1 line to convert 'Rock' to 1. It does not work that way. The most basic way to do this is with another if..elif block, but a dictionary would be better:

player1 = input("Player One do you want Rock, Paper, Scissors, Lizard or Spock?")
player2 = input("Player Two do you want Rock, Paper, Scissors, Lizard or Spock?")
print(player1)
print(player2)

d = {'Rock':1, 'Paper':2, 'Scissors':3, 'Lizard':4, 'Spock':5}

player1 = d.get(player1)
player2 = d.get(player2)

Upvotes: 6

Related Questions