擅长:python、mysql、java
<p>如果Python中的方法没有<code>return</code>语句,则返回的默认值是<code>None</code>。这就是你看到的。你知道吗</p>
<p>要阻止这种情况发生,只需添加一个返回值。对于您的另一部分,要退出应用程序,只需在循环的其余部分开始之前,首先检查此人是否要退出。你知道吗</p>
<pre><code>import sys
def interact():
print "Welcome to calculator"
print
c = raw_input("Command: ")
# Just do the check here, so you don't bother running the rest of the code
if c == 'x':
sys.exit()
print
d = c.split()
while True:
if d[0] =='date' and len(d) == 2:
print display_stats(d[1])
elif c == 'q':
return
else:
print "Unknown Command: ",c
break
return '' # Return a blank string
</code></pre>