def fib(n): rt.pause() if n <= 1: return n else: child = rt.spawn(fib, (n-2,)) return fib(n-1) + child.wait()
def test(raw_text): raw_text = raw_text.strip() rt.pause() text = Text(raw_text) print("The text you entered is: {}".format(raw_text)) num_words = text.compute_number_of_words(make_bool()) print("The text has {} words.".format(num_words)) return num_words
def factorial(n): if n == 0: return 1 else: print("n = %d" % n) if n % 10 == 0: rt.pause() return n * factorial(n - 1)
def factorial(n): result = 1 for i in range(1, n + 1): if i % 10 == 0: rt.pause() print("i = %d" % i) result *= i return result
def factorial(n): steps = 0 result = 1 while n > 0: steps += 1 if steps % 10 == 0: rt.pause() print("n = %d" % n) result = result * n n -= 1 return result
def my_range(n): l = [] i = 0 while i < n: print("my_range: i = ", i) l.append(i) i += 1 if i % 20 == 0: rt.pause() return l
def main(n): """Prints out all odd numbers less than sqrt(n).""" for x in range(n): rt.pause() if x * x > n: break if x % 2 == 0: continue print(x) return {}
def main(): a1, a2, a3, a4 = 1, 2, 3, 4 rt.pause() [b1, b2, b3, b4] = 1, 2, 3, 4 rt.pause() c1, c2, c3, c4 = [1, 2, 3, 4] rt.pause() [d1, d2, d3, d4] = [1, 2, 3, 4] rt.pause() print(a1, a2, a3, a4) print(b1, b2, b3, b4) print(c1, c2, c3, c4) print(d1, d2, d3, d4)
def return_true(i): print("return_true: i = ", i) if i % 20 == 0: rt.pause() return True
def __init__(self, text): self.text = text print("Pausing inside __init__().") rt.pause() self.pattern = re.compile(r"\w+")
def make_bool(): rt.pause() print("I feel like pausing.") return True
def compute_number_of_words(self, _unused): # The unused param is used to force pickling of this method. words = re.findall(self.pattern, self.text) rt.pause() return len(words)