Michael Dawson says in his book Python Programming (Third Edition, page 14) that if I enter input("\n\nPress the enter key to exit.") when the user presses the Enter key the program will end.
I have tried this several times and it doesn't happen. I have tried using Python 3.1 and 3.3. Help would be appreciated.
This is a fairly straightforward concept, do take a look at this example
x = input("Hit Enter to Exit, or Input any other key to continue ")
if not x :
print("Exiting the Program.")
exit()
else:
a = int(input("\nEnter a Number : "))
b = int(input("Enter another Number : "))
print("Sum of the two numbers : ", a+b)
The input() function merely waits for you to enter a line of text (optional) till you press Enter. The sys.exit("some error message") is the correct way to terminate a program. This could be after the line with the input() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With