Note that there are some explanatory texts on larger screens.

plurals
  1. POSingPath and Python Help! - Infinite loop error in "Create a Problemset Mode"
    text
    copied!<p>SingPath is an interactive problem set website that tracks your progression within multiple programming languages. Unfortunately it has some bugs. The largest is the error:</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>appearing multiple times when you run your problem set code. Now all you have to do to correct the bug while answering a problem set question is to just rerun the code.</p> <p><strong>However</strong>, within the problem creator it creates a HUGE issue. Essentially you can run the code until it works in the creator as well which is not the problem for testing. The issue stems from submitting the <code>problem/solution</code> due to the fact that the submit button reruns the code. This means you need to get two consecutive correct answers which are near impossible to get (I've been trying for an hour now). The fact that <em>creating</em> a problem is required to continue within the problem set is quite ruined on the buggy creator.</p> <p>So (finally) here's my question, How can I make the following code run without this error in the creator?</p> <p>Code:</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>Sample function calls:</p> <pre><code>&gt;&gt;&gt; string3('abc') 'True' &gt;&gt;&gt; string3('a2d') 'True' &gt;&gt;&gt; string3('234') 'True' </code></pre> <p>What the code does:</p> <p>The Infinite Monkey Theorem states that</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>Create a function <code>string3</code> that would randomly generate strings of 3 characters until those character's are equal to the string received from the function. Hint: Search for a random string generator for reference. All characters in a string will be lower case.</p> <p>I am a beginner programmer and I would like if some comments were put it so I can understand more complicated solutions although I would be grateful for any help/suggestions!</p> <p>Also, I have already notified the support staff at SingPath for the bug but I would like to get as much practice in today as I can! If it's impossible to potentially fix the bug on the client side I completely understand! Best of luck!</p> <p><strong>IMPORTANT EDIT</strong></p> <p>I forgot to mention that this bug will happen regardless of loops within the code. While my program is very intense with the constant random assignment of characters I know it isn't the issue (it might be AN issue but not THE issue XD). If you don't believe me try to create a problem here: <a href="http://singpath.appspot.com/" rel="nofollow">http://singpath.appspot.com/</a></p> <p>Even a simple function declaration and return such as:</p> <pre><code>def add_one(n): return n+1 </code></pre> <p>Can cause the loop bug! If I can do anything on my side (exception statement?) Please let me know!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload