如果您使用的是python,根据您的sintax,您可以执行以下操作:import sys # if you want this what i said in later text...`
movex = raw_input("\nDesired X position, or quit >> ")
if movex == "q":
break
# don't really know what you want to do with this but i think you want to use sys.exit() to quit your porgram
movey = raw_input("\nDesired Y position, or quit >> ")
if movey == "q":
break #same as in first...
try:
movex_int = int(movex)
movey_int = int(movey)
if movex_int < gsize and movex_int >= 0:
#Do stuff
if movey_int < gsize and movey_int >= 0:
#Do stuff
except ValueError: #if not an int the user didn't enter "q" but not either a number
sys.exit() #this will exit program because parameters aren't expected, but you can do what you want
对于python3,只需使用input而不是raw_input:)