I am writing a security system that denies access to unauthorized users.
import sys
print("Hello. Please enter your name:")
name = sys.stdin.readline().strip()
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.
No comments:
Post a Comment