I am starting to learn python. I have gone through several tutorials and now I am trying to write my first script. It is a simple console menu. I am running Python 2.6.5 under cygwin.
Here is my script:
import sys
print "********************************************************************"
print "** 1) This is menu choice #1 **"
print "** **"
print "** **"
print "** **"
print "** **"
print "** **"
print "********************************************************************"
print
print "Choice ?"
choice = sys.stdin.readline()
print "You entered: " + choice
if choice == 1:
choice1 = sys.stdin.readline()
print "You entered:" + choice1
else:
quit()
print "Exiting"
When I run the script, I get to the Choice? prompt. I enter 1 and I get the “You entered:” message and then the script exits without displaying the “Exiting” message.
Seems like it should be so easy. Thanks in advance for any help.
You’re comparing a string to an integer. Try converting the string into an integer: