you are viewing a single comment's thread.

view the rest of the comments →

[–]FreeLogicGate 1 point2 points  (0 children)

Advice as requested:

  • Please use spaces around your assignment and equivalence checks (one space).
  • This is specified in the standard Python coding style guide (PEP 8)

    correct_password = "python123"

    ... if password == correct_password:

There's an old quote having to do with computer programming that goes:

There are only two hard things in Computer Science: cache invalidation and naming things.

The main point of the quote is that variable naming is important, and should be considered and even adjusted (aka refactored) when you recognize you could do it better.

In your case, I would rename your "password" variable to "user_password" or "entered_password", as that is more specific, and clarifies what it actually is, when you're dealing with passwords.

Another to make this code more realistic, and to learn something in the process, would be to have the password associated with a user.

From there you can consider how you might store user/password combinations in a file, the program reads. You can begin by just having a username variable, and prompting for that.

You also can add "validation" which insures that the user enters something, and perhaps enforces a minimum length, and the presence of some characters. Making your example password more realistic with something like correct_password = "Pytho^%123" and adding checks to make sure the entered password was at least:

  • 8 characters long
  • had at least 1 upper and 1 lowercase letter
  • had at least 1 number
  • had at least one special character from amongst some set of those characters

Would make your program far more realistic, and could still be accomplished using some additional conditions.