擅长:python、mysql、java
<p>尝试以下操作:</p>
<pre><code>def loop(rep=None):
rep=rep if rep else set() #use a set or list to store the responses
response=raw_input("enter something : ")
if response not in rep: #if the response is not found in rep
rep.add(response) #store response in rep
print "hello"
loop(rep) #pass rep while calling loop()
else:
print "You've already said {0}".format(response) #if response is found
loop(rep)
loop()
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>enter something : hi
hello
enter something : hi
You've already said hi
enter something : foo
hello
enter something : bar
hello
enter something : bar
You've already said bar
enter something :
</code></pre>
<p>另外,还要给<code>loop()</code>添加一个中断条件,否则它将是一个无限循环</p>