0

Im trying to create a basic rock, paper, and scissors game. At first I was using == signs instead of in but a part of the code would not proceed after that step. I changed the == to in as someone did in another question, however, the rest of he code now doesnt work. For example, if I input rock and rock it would output tie but if I input rock and paper there would be no output. I am pretty confident the problem is somewhere in the if and elif statements.

input_a = input("player a enter rock, paper, or scissors")
input_b = input("player b enter rock, paper, or scissors")



if input_a and input_b in ("rock","paper","scissors"):
    if input_a == input_b:
        print("it is a tie")
    elif input_a == "rock" and input_b == "scissors":
        print("a wins")
    elif input_a == "paper" and input_b == "rock":
        print("a wins")
    elif input_a == "scissors" and input_b== "paper":
        print("a wins")
else:
        print("invalid input")   
  • Your first `if` condition checks whether (`input_a` resolves to `True` or `False`) and (`input_b` in (rock, paper, scissors)) which is not what you want. Hence, you should re-write it as per @MrGeek 's answer – ksha Aug 26 '19 at 21:57
  • @Ketan if i wanted to change from using in to equal signs how would i write that? would i have to write them seperately? – user11975207 Aug 27 '19 at 00:17
  • you won't want to do that since you will have to cover all combinations of (x == 'foo' AND y == 'foo') OR (x == 'foo' AND y == 'bar') OR ... which are 9 in this case. – ksha Aug 28 '19 at 11:08

2 Answers2

0

This is an invalid conditional

if input_a and input_b in ("rock","paper","scissors"):

You need to instead use

if input_a in ("rock","paper","scissors") and input_b in ("rock","paper","scissors"):
Mike
  • 1,471
  • 12
  • 17
0

Change:

if input_a and input_b in ("rock","paper","scissors"):

To:

allowed = ("rock", "paper", "scissors")

if input_a in allowed and input_b in allowed:

The variable allowed is used to avoid repetition.

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55