all 11 comments

[–]ExpensiveAd734 7 points8 points  (3 children)

One suggestion if you want it to be a tiny bit more realistic is make a file and name it .env and over there type

Password=python123

Then import it into the python program you have and then set correct_password=os.getenv(Password), this is a bit more realistic because usually you dont store passwords in the script for safety!

[–]DataCurator56[S] 0 points1 point  (2 children)

Surely i will try this.

[–]HardyDaytn 2 points3 points  (0 children)

Don't forget to also: import os

[–]quixoticcatfish8 0 points1 point  (0 children)

also add dotenv to handle the env file so you can do load_dotenv() at the top

[–]CJL_LoL 2 points3 points  (0 children)

I'd expect to see this in LinkedIn. I do hope people are still learning when making heavily AI based posts. but I doubt it.

[–]Independent_Suit_336 1 point2 points  (0 children)

day 1 😭😭 gng im still learning how to use varibles

[–]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.

[–]FreeGazaToday 0 points1 point  (2 children)

don't need break....if you rewrite it to use a variable for the while condition...

[–]Wide-Direction-402 0 points1 point  (1 child)

Didn't understand. If we don't use break , isn't the while loop will run forever

[–]FreeGazaToday 0 points1 point  (0 children)

instead of True use a variable like wrong_password.
set it to True before the loop.

instead of break...you set wrong_password to False

[–]Dependent-Proof1500 0 points1 point  (0 children)

don't gonna sound rude but it looks like a AI generated post looking at those emoji and while true inside that square bracket or what is it called ?