检查用户是否输入了数字.不要信

Mar*_*ham 0 python

我想知道检查用户键入字母与数字的最简单方法.如果用户输入一个字母,它会给他们一个错误信息并回答他们的问题.现在我拥有它,所以当用户输入'q'时它将退出脚本.

if station == "q":
        break
else:
        #cursor.execute(u'''INSERT INTO `scan` VALUES(prefix, code_id, answer, %s, timestamp, comport)''',station)
        print 'Thank you for checking into station: ', station
Run Code Online (Sandbox Code Playgroud)

我需要它回到问路站的问题.

YeJ*_*bin 5

只需使用python内置方法

str.isdigit()
Run Code Online (Sandbox Code Playgroud)

请参阅http://docs.python.org/library/stdtypes.html

例如

if station.isdigit():
   print 'Thank you for checking into station: ', station
else:
   # show your error information here
   pass
Run Code Online (Sandbox Code Playgroud)