I want to create a password program that checks to see if a special character is inside an input.
So I created a list with some special characters so that if just one or multiple symbols are detected in the input, then it should do something:
SpecialSymbols =['$', '@', '#', '%']
Password = input("type password")
if Password in SpecialSymbols:
print("strong password")
else:
print("no special character detected")
I think I need to use a for loop as well in which case it prints all items. Or I may need to check just specific characters and not the entire input, how do I do this?
You can use any (if there should be at least one special char from the list) or all if there must be all special chars from the list in the input string.
if any(x in SpecialSymbols for x in Password):
if all(x in SpecialSymbols for x in Password):
See a Python demo:
SpecialSymbols =['$', '@', '#', '%']
Passwords = ["String #$%@", "String #1", "String"]
for Password in Passwords:
if any(x in SpecialSymbols for x in Password):
print("strong password")
else:
print("no special character detected")
Output for this snippet:
strong password
strong password
no special character detected
Loop through the string
SpecialSymbols =['$', '@', '#', '%']
Password = input("type password")
strong = False
for c in Password:
if c in SpecialSymbols:
strong = True
break
if strong:
print("Password is strong")
else:
print('password is weak')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With