コード例 #1
0
def fib(n):
    rt.pause()
    if n <= 1:
        return n
    else:
        child = rt.spawn(fib, (n-2,))
        return fib(n-1) + child.wait()
コード例 #2
0
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
コード例 #3
0
def factorial(n):
    if n == 0:
        return 1
    else:
        print("n = %d" % n)
        if n % 10 == 0:
            rt.pause()
        return n * factorial(n - 1)
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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 {}
コード例 #8
0
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)
コード例 #9
0
def return_true(i):
    print("return_true: i = ", i)
    if i % 20 == 0:
        rt.pause()

    return True
コード例 #10
0
 def __init__(self, text):
     self.text = text
     print("Pausing inside __init__().")
     rt.pause()
     self.pattern = re.compile(r"\w+")
コード例 #11
0
def make_bool():
    rt.pause()
    print("I feel like pausing.")
    return True
コード例 #12
0
 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)