2
print ('Password Request Initiative')

password = 'abcd'
user_input = input('Please Enter Password: ')

if user_input != password:
    print("Haha. Nope") 
    quit()

elif user_input == password:
            print ("User is now logged in...")
    enter code here

that's the code, but when I run it and type the wrong password it shows this warning:And I want it to run without this message so it just instantly closes

Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
Amachyure
  • 31
  • 1
  • 3
  • 1
    What happens if you change `quit()` to `exit()` or `sys.exit()`? You need to `import sys` first to make that last one work. – PM 2Ring Jun 25 '16 at 11:49
  • See here: http://stackoverflow.com/questions/19747371/python-exit-commands-why-so-many-and-when-should-each-be-used – joel goldstick Jun 25 '16 at 12:08
  • I don't get when message when trying to `quit()`. **How** are you running that code? – Bakuriu Jun 25 '16 at 12:17
  • Those solutions aren't what the person is looking for. The intended solution is for the Python shell to close upon exit, but without a prompt as called by `exit()` or `quit()`. – Bink Jun 25 '16 at 14:48
  • closely related to [Close Python IDLE shell without prompt](http://stackoverflow.com/questions/37839234/close-python-idle-shell-without-prompt/37841282#37841282) Although that person was creating the idle shell manually in their code. – Tadhg McDonald-Jensen Jun 25 '16 at 15:38
  • Is quit() method defined with proper exit? May be a long running process inside quit would be preventing the program to terminate! – Swadhikar Jun 25 '16 at 15:55

1 Answers1

2

To avoid the message when running from IDLE, do not use quit() or exit() in a program. They are not part of the language and are not intended for this use. They are (usually) added by the site package for interactive use only. In particular, they were added so that people could more easily exit the interactive interpreter when running in a terminal window -- without knowing the magic control code needed on a particular system -- and without closing the terminal window itself.

C:\Users\Terry>python
Python 3.5.1 ... [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
SyntaxError: invalid syntax
>>> ^Z
C:\Users\Terry>python

On Unix, ^D, End of File, exits, but on DOS and still on Windows, ^Z<Return> is used instead. Few beginners know this. Other interactive programs use quit and exit, so we added those as synonyms.

With IDLE, ^D in the shell closes the shell on all systems, but not editor windows. It is the same as clicking the close button on the title bar. At least on Windows, ^Q == quit() and closes everything.

To exit a program when not as the bottom of a file, use raise SystemExit or sys.exit().

As the expansion of the acronym says, IDLE is a development environment. It is a feature of IDLE that testing a program within IDLE does not kill IDLE itself, at least not without warning.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52