2024-04-23 20:17:06 发布
网友
如何强制用户输入整数?我想知道我是否需要一个“暂时”的声明。这是我从here得到的想法。你知道吗
x = raw_input("put in a number") def RepresentsInt(s): try: int(s) return True except ValueError: return False
这样的方法应该有用:
while True: try: x = int(raw_input("put in a number")) break except ValueError: continue # or maybe print a message here...
这样的方法应该有用:
相关问题 更多 >
编程相关推荐