-5

How can I make this loop, and if possible is there anyway I can tidy it up?

l,a,b, = 0, 0, 0
password = str(input("Please enter a strong, 12 character password: "))
for i in password:
 if password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or 
[12].islower():
  l+=1
if password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or 
[12].isupper():
a+=1
if len(password) == 12:
b+=1
if l>=1 and a>=1 and b>=1:
print("valid password")
else:
print("invalid password")
  • 1
    Note that your code absolutely does not do what you expect. `[1]` is just a single-element list of an integer, for example. Hence the `AttributeError` you're presumably asking about (although you don't mention it). – jonrsharpe Nov 08 '20 at 20:25
  • 1
    How about you describe what you're trying to do, because whatever it is, this code does not do it. – khelwood Nov 08 '20 at 20:26
  • 1
    You need to do something like `any(map(password, lambda x: x.islower()))` instead. – user Nov 08 '20 at 20:27
  • @khelwood, I agree – Паша Мороз Nov 08 '20 at 20:27
  • 1
    What would be the expected input criteria? Contains a 12 long array of both lower and upper characters of the alphabet of your choice? – nagyl Nov 08 '20 at 20:27
  • 1
    If you gonna write a password strength checker, there's a better way. – Pouya Esmaeili Nov 08 '20 at 20:28
  • 1
    "Make this loop" does not tell us what you want to do. We expect you to use existing tutorials and other materials before posting here -- you need to learn how to write a compound Boolean expression, and you need to research existing password checkers. You have several errors in your code; please clean it up to where you're asking about only *one* problem. – Prune Nov 08 '20 at 20:36
  • ` password[0] or [1] or [2] or [3] or [4] or [5] or [6] or [7] or [8] or [9] or [10] or [11] or [12].isupper():` doesn't do what you think it does – Jean-François Fabre Nov 08 '20 at 20:38
  • @prune the code runs fine, there are no errors, it is a password checker, but if the password is invalid i want it to loop the question again. – mr_freddy Nov 08 '20 at 21:10
  • @khelwood the code runs fine, there are no errors, it is a password checker, but if the password is invalid i want it to loop the question again – mr_freddy Nov 08 '20 at 21:10
  • The code you have posted does not run fine. It has multiple errors. Even if you fixed the indentation so it can be run, it still would not do what it is supposed to do. – khelwood Nov 08 '20 at 21:43
  • @khelwood, works fine for me idk why its not for you, some one has posted an answer anyway so thank you – mr_freddy Nov 08 '20 at 22:03
  • @mr_freddy if the provided answer works, it would be nice to mark as accepted. – nagyl Nov 08 '20 at 22:55
  • @nagyl sorry, im new to thi, how can i mark as accepted?? – mr_freddy Nov 09 '20 at 00:19
  • In that case, this is a duplicate of https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – Prune Nov 09 '20 at 00:31
  • 1
    @mr_freddy It did not work fine for you. You just didn't test it very thoroughly. – khelwood Nov 09 '20 at 00:34

1 Answers1

2
  1. Cleaner code:
l, a, b, = 0, 0, 0
password = str(input("Please enter a strong, 12 character password: "))
for i in password:
    if i.islower():
        l += 1
    if i.isupper():
        a += 1
if len(password) == 12:
    b += 1
if l >= 1 and a >= 1 and b >= 1:
    print("valid password")
else:
    print("invalid password")
  1. What about non-letter characters like ":"?
Cutewarriorlover
  • 158
  • 2
  • 11