Hey guys I am new to Python and I wrote this password program in Python but the first 'elif' statement doesn't execute for some reason. If i input a password that has less than 5 characters AND has a special character in it, it just says that it's too short whereas it's supposed to say it's too short AND you can't use special characters. Any help would be appreciated.
password = 'Chubz'
count = 3
listA = list("'#$%&\()@*+,-./:;?@[\\]^_`{|}~ \t\n\r\x0b\x0c'")
while count >= 0:
x = input('What is the pass? ')
if x in listA:
print(f" {count} You can't use special characters ")
count -= 1
elif x in listA and len(x) < 5:
print(f"{count} You can't use special characters and the pass is too short")
count -= 1
elif len(x) < 5:
print(f'{count} Pass is too short')
count -= 1
elif x != password:
print(f'{count} Try again')
count -= 1
else:
print('Access Granted')
break
xis a string. You want to check if any of characters withinxis a special character. To do that, you have to iterate throughx. You cannot just doif x in listA