0

I have this code which should return true if the input string is one of those words (Helen, Maria, John) otherwise it should return false. But after i put a name i get no result.

name=input("Introduceti un nume:")
def find_name():
  if (name) == 'John' or 'Helen' or 'Maria' in:
   return True
  else:
     return False
  find_name()
  • This does not look much like python! You will need to read about conditions but what you are asking for can be done with: `name in {"John", "Helen", "Maria"}`. The result of `in` operator is boolean – urban Sep 06 '20 at 11:38
  • If that's your actual indentation - it is wrong. You call the function recursively inside itself. You might want to un-indent the `find_name()` call – Tomerikoo Sep 06 '20 at 11:38
  • 1
    Just do `return name in {'John','Helen','Maria'}`, When you return True/False after a if, just return the condition itself – azro Sep 06 '20 at 11:40
  • @azro The same sort of issue, but in some sense the question is the opposite of the proposed duplicate. This question is how to test multiple *values* against a variable. This is clearly a duplicate, but I don't know of a good dup target. – John Coleman Sep 06 '20 at 11:40
  • `if boolean_condition return True else return False` is just a needlessly verbose way of saying `return boolean_condition` – John Coleman Sep 06 '20 at 11:42
  • @JohnColeman maybe you will like this one better? https://stackoverflow.com/questions/7713700/check-variable-if-it-is-in-a-list – Tomerikoo Sep 06 '20 at 11:43
  • @Tomerikoo The underlying issue is the misuse of `or`, so the proposed duplicate is fine. I was being a bit pedantic – John Coleman Sep 06 '20 at 11:45
  • @JohnColeman I understand and agree with you. I marked the first one as a duplicate as well because if you simply change the roles of the values and variables, it becomes an exact duplicate – Tomerikoo Sep 06 '20 at 11:47

1 Answers1

1
name=input("Introduceti un nume:")
def find_name():
    if (name) in {'John','Helen','Maria'}:
        return True
    else:
        return False
find_name()
IoaTzimas
  • 10,538
  • 2
  • 13
  • 30