+ 1

Why this code don't work

password=input() sympols=['#','

#x27;,'&','!','@'] if sympols in password: print("Strong password") else: print("Weak password")

19th Aug 2024, 2:31 PM
Ali Abdelhamid
Ali Abdelhamid - avatar
5 Answers
+ 2
The code doesn't work because the in operator is used incorrectly. The in operator checks if a single element is present in a sequence (such as a list or string), but in this case, you're trying to check if a list of symbols is present in a string. Instead, you should check if any of the symbols in the list are present in the password string. You can do this using the any function and a generator expression. Here's the corrected code: password = input() symbols = ['#', '
#x27;, '&', '!', '@'] if any(symbol in password for symbol in symbols): print("Strong password") else: print("Weak password") This code uses the any function to check if any of the symbols in the symbols list are present in the password string. The generator expression symbol in password for symbol in symbols iterates over the symbols in the list and checks if each one is present in the password string. If any of them are, the any function returns True, and the code prints "Strong password". Otherwise, it prints "Weak password".
19th Aug 2024, 3:17 PM
Blue Astroblossom☄️
Blue Astroblossom☄️ - avatar
+ 4
Lothar ok bro ☺️🤗 Thank you for your feedback✨. I understand your point about the importance of providing hints and tips rather than ready-made code. I'll make sure to incorporate more guidance in my future responses to help the original poster learn and find solutions independently. Your input is valuable and helps improve the quality of our community support and our ideas. Thanks again 🔥🤗
20th Aug 2024, 9:10 PM
Blue Astroblossom☄️
Blue Astroblossom☄️ - avatar
+ 3
Blue Blossom , it is not seen as very helpful when we are going to post a ready-made code,. it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself.
19th Aug 2024, 5:12 PM
Lothar
Lothar - avatar
+ 1
Ali Abdelhamid , do you expect to have one of the symbols in the password, or 2, ... or all? btw: we can not do like: `if symbols in password`, we have to check for *each* symbol individually if it is in `password`.
19th Aug 2024, 2:36 PM
Lothar
Lothar - avatar
+ 1
password = input("Enter your password: ") symbols = ['#', '
#x27;, '&', '!', '@'] if any(symbol in password for symbol in symbols): print("Strong password") else: print("Weak password")
21st Aug 2024, 9:14 AM
Vivek Mithiya
Vivek Mithiya - avatar