<p>SingPath是一个交互式问题集网站,它跟踪你在多种编程语言中的进度。不幸的是它有一些错误。最大的错误是:</p>
<blockquote>
<p>Your code took too long to return. Your solution may be stuck in an infinite loop. Please try again.</p>
</blockquote>
<p>运行问题集代码时出现多次。现在,在回答问题集问题时,要纠正错误,只需重新运行代码。在</p>
<p><strong>然而</strong>,在问题创造者内部,它产生了一个巨大的问题。实际上,您可以运行代码,直到它在creator中工作为止,这不是测试的问题。这个问题源于提交<code>problem/solution</code>,因为提交按钮会重新运行代码。这意味着你需要连续得到两个几乎不可能得到的正确答案(我已经试了一个小时了)。事实上,创造一个问题需要在问题集中继续下去,这个事实在buggy的创造者身上被彻底破坏了。在</p>
<p>所以(最后)我的问题是,如何使下面的代码在creator中不出现这个错误呢?在</p>
<p>代码:</p>
<pre><code>import string
import random
# Takes a blank string then replaces it with 3 random letters/numbers.
def string3(s1):
s2 = ''
def randstring (size = 3, chars = string.ascii_lowercase + string.digits):
a = ''.join(random.choice(chars) for x in range(size))
return a
''' If the string brought in isnot equal to the string generated keep
rerunning the random string generator '''
while s1 != s2:
s2 = randstring()
return 'True'
</code></pre>
<hr/>
<p>函数调用示例:</p>
^{pr2}$
<p>准则的作用:</p>
<p>无限猴子定理指出</p>
<blockquote>
<p>Given enough time, a hypothetical monkey typing at random would, as part of its output, almost surely produce all of Shakespeare's plays.</p>
</blockquote>
<p>创建一个函数<code>string3</code>,它将随机生成3个字符的字符串,直到这些字符与从函数接收到的字符串相等为止。提示:搜索随机字符串生成器以供参考。字符串中的所有字符都是小写。在</p>
<p>我是一个初学者程序员,我想如果有一些意见,我可以理解更复杂的解决方案,虽然我会很感激任何帮助/建议!在</p>
<p>另外,我已经通知了SingPath的支持人员,但是我希望在今天得到尽可能多的练习!如果不可能修复客户端的错误,我完全理解!祝你好运!在</p>
<p><strong>重要编辑</strong></p>
<p>我忘了提到无论代码中的循环如何,都会发生这个bug。虽然我的程序非常紧张,不断随机分配字符,但我知道这不是问题所在(这可能是个问题,但不是问题XD)。如果你不相信我,试着在这里制造一个问题:<a href="http://singpath.appspot.com/" rel="nofollow">http://singpath.appspot.com/</a></p>
<p>即使是简单的函数声明和返回,例如:</p>
<pre><code>def add_one(n):
return n+1
</code></pre>
<p>会导致循环错误!如果我能帮我做点什么(例外声明?)请告诉我!在</p>