Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Last active January 15, 2017 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kwpolska/c7dff794429d202a9c622e669cd5d588 to your computer and use it in GitHub Desktop.
Save Kwpolska/c7dff794429d202a9c622e669cd5d588 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from __future__ import print_function
def f(n, level=0):
indent = level * ' '
print(indent, 'start', n)
if n == 10202:
print(indent, 'return constant from', n)
return 4
re = f(n ** 2 + 1, level + 1)
print(indent, 'continue', n)
s = 2 * n * re
print(indent, 's =', s)
print(indent, 'return from', n)
return s
f(3)
# start 3
# start 10
# start 101
# start 10202
# return constant from 10202
# continue 101
# s = 808
# return from 101
# continue 10
# s = 16160
# return from 10
# continue 3
# s = 96960
# return from 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment