Can you make a simple "Enter password" program for me in Python please so I can study it?

I made one 3 months ago but then life stuff happened and got a new laptop now I am trying to teach myself python again and lost my self study files. Less than 10 lines please, I think mine was like 5 lines it was pretty straight forward using: If, input() and variables, else, print()

Also I want it to loop back to "Access Denied" every time password is wrong and when password is right I want it to say "Access Granted". There should be a pause at the end where it says "Please type anything/press enter to exit" after correct password is inputted.

Thank you in advance fellow humans :)

3 Answers

  • 1 month ago
    Favourite answer

    running = True


      password = input('Enter a Password\n')

      realpass = "12345"

      if (password == realpass):

        print("Access Granted")

        password = input('press enter to exit')

        running = False


        print("Access Denied")

    # little bit excessive with while loop but that's the best i can do

  • 1 month ago

    The normal input functions don't let you control echoing the password back.  Python has a special module in the standard library that you should use to get a password in at the console.

        import getpass # do this once at the top

        pw = getpass.getpass() # get password with the default "Password: " prompt

        pw = getpass.getpass("Tell me your secret: ") # get password with custom prompt

    This won't work in IDLE under Windows and may not work properly in IDLE under Linux/Unix/MacOS.  This is really for console or terminal windows only.  (A GUI like Tkinter or wxPython will have different ways to enter passwords.)

  • EddieJ
    Lv 7
    1 month ago

    while input ("Password: ")!="abc": print ("Access denied")

    print ("Access granted")

Still have questions? Get answers by asking now.