0

I am trying to create an if statement that checks whether certain combinations of unordered values are in my appended list.

if ("1" and "2" and "3") or ("1" and "4" and "7") in player1_inputs: 
    print("Correct")
else:
    print("Incorrect")

No matter what set of numbers I put in the player1_inputs, I always get "Correct". Could anyone explain why this is the case?

Keperoze
  • 63
  • 4
  • `("1" and "2" and "3") == "3"`, `("1" and "4" and "7") == "7"` – ForceBru May 06 '20 at 12:00
  • Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – mkrieger1 May 06 '20 at 12:02
  • 2
    Conditions are supposed to be explicit, i.e. you can't do `"1" and "2" in X` but you'll have to do `"1" in X and "2" in X`. What you're better off using is `set()`, and use `issubset()` instead of checking like you did – Zionsof May 06 '20 at 12:02
  • This should be the answer @Zionsof. – picklu May 06 '20 at 13:31

1 Answers1

1

You could use set logic for that:

player_inputs = {'1', '2', '3', '4', '7'}

subsets = [{'1', '2', '3'}, {'1', '4', '7'}, {'3', '4', '5'}]

for subset in subsets:
    if subset.issubset(player_inputs):
        print('Correct')
    else:
        print('Incorrect')
mapf
  • 1,906
  • 1
  • 14
  • 40