擅长:python、mysql、java
<p>你的程序流程有点内翻,我可以提出一些改进意见吗?在</p>
<pre><code>def askNumber():
"""Asks the number to test"""
while True:
a = raw_input("Select the number to test (type 'exit' for leaving):")
if not a:
print "Your input can't be 'empty'"
continue
if a.lower() == "exit":
answer()
break
try:
b = int(a)
except ValueError:
print "Your input is not valid. Please enter a 'number'!"
continue
processing(b)
</code></pre>
<p>实际上,<code>not a</code>分支也可以消除(空输入将在<code>except</code>中处理)。在</p>