-3

I've written the following code and if the else statement is true I would like the program to shutdown. I'm new to python and having some trouble

password = raw_input('Enter yes to continue:')
if password == 'yes':
    print'You have chosen to continue' 
else:
    print'You have chosen to exit'
Barranka
  • 20,547
  • 13
  • 65
  • 83
goat
  • 13
  • 1
  • 4

2 Answers2

0

Add this to your code

import sys # This goes at the header
...
if password == 'yes'
    pass # Your code goes on... I put the 'pass' just as a place holder
else
    sys.exit()
Barranka
  • 20,547
  • 13
  • 65
  • 83
  • my code now looks like this import sys password = raw_input('Enter yes to continue:') # Determine if yes or anything was entered was entered. if password == 'yes': print'You have chosen to contiue' else: print'You have chosen to exit' sys.exit I want the python program to shut down or at least the interactive window but im not getting results, please help, am I missing something? – goat Apr 28 '13 at 15:22
  • by "shutdown" you mean exit the program? or do you mean something else? – Barranka Apr 29 '13 at 03:54
  • @MarkKearney I've corrected a typo... instead of `sys.exit` it *must* be `sys.exit()` – Barranka Apr 29 '13 at 04:16
  • exit the program or is there a shutdown python function? – goat Apr 29 '13 at 11:37
  • @MarkKearney just `sys.exit()`. It ends the python program. If you called the program from the console (or command window in Windows), it stops the execution and exits the program, and returns to the system prompt. – Barranka Apr 29 '13 at 15:48
0
import sys

if condition is true:
    pass
    # or your operating row.
else:
    sys.exit()
jeyraof
  • 863
  • 9
  • 28