Skip to content

Instantly share code, notes, and snippets.

@Yourun-proger
Last active June 3, 2022 14:36
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 Yourun-proger/24d35bb8fff2dd1fcfae54572b1559a2 to your computer and use it in GitHub Desktop.
Save Yourun-proger/24d35bb8fff2dd1fcfae54572b1559a2 to your computer and use it in GitHub Desktop.
def add(x=None):
if x is None:
return getattr(add, 'result', 0)
else:
if hasattr(add, 'result'):
add.result += x
else:
setattr(add, 'result', x)
return add
print(add(1)(2)(3)()) # 6
@Yourun-proger
Copy link
Author

Task

You need to make the add function that has the following behavior:

print( add(1)(2)(3)() ) # 1 + 2 + 3 = 6
>>> 6

Disclaimer

I don't know where the original task is, I remember seeing it somewhere in Python chat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment