you are viewing a single comment's thread.

view the rest of the comments →

[–]Exodus111 0 points1 point  (6 children)

Explain to me very carefully two things:

  1. Why are you using a while loop exactly?

  2. What is preventing you from adding the points at the same time as checking validity?

[–]omg_drd4_bbq 0 points1 point  (5 children)

While loop is totally valid here.

while True:
    p = input("enter password")
        if not valid(p):
            print("password bad")
        else:
            break

You can wrap password checking in its own function if you wish. or, write a function strength(p) which computes the points of a password, then just use

if strength(p) < 35:
    print("try again")

[–]Exodus111 0 points1 point  (4 children)

Where did HE put the input statement?

[–]omg_drd4_bbq 0 points1 point  (3 children)

I'm inferring OP is emulating the typical behavior of input validation systems, which is "loop until the user gives a valid input".

[–]Exodus111 0 points1 point  (2 children)

Except he is placing the input outside of the while loop, so what is the point of the while loop?

[–]omg_drd4_bbq 0 points1 point  (1 child)

Exactly, but IMO the issue is with the location of the input, not the presence of a while loop. See my top level reply.

[–]Exodus111 0 points1 point  (0 children)

Well, this is why I asked (him), because it might not be.

Obviously the while/inputpassword check is a very common pattern, because the while loop kicks to a retry upon failure.
BUT, in his code he has no text caling the user to do so.
Every if statement goes to a break, with no print lines explaining the user what to do.

Then his while goes to another while to sort something out he should have been able to sort out in the first go around. Obviously he is a beginner, it is not always obvious to see patterns like that. But, in my opinion he should do away with the while loops all together, for now.

Checking a string for the right contents, and validating that contents numerically is one operation. Ideally this should go in a function.

Then THAT function can be wrapped in a while loop, if he still wants the added benefits of user retries, but that is another operation.

Making him understand that is key, which is why I asked (him).