on-internet
← Community

Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those?

Stack Overflow ·

I am writing a security system that denies access to unauthorized users. name = input("Hello. Please enter your name: ") if name == "Kevin" or "Jon" or "Inbar": print("Access granted.") else: print("Access denied.") It grants access to authorized users as expected, but it also lets in unauthorized users! Hello. Please enter your name: Bob Access granted. Why does this occur? I've plainly stated to only grant access when name equals Kevin, Jon, or Inbar. I have also tried the opposite logic, if "Kevin" or "Jon" or "Inbar" == name, but the result is the same. This question is intended as the can

Comments

Sign in or sign up to comment and upvote.

No comments yet.