Last active
June 3, 2022 14:36
-
-
Save Yourun-proger/24d35bb8fff2dd1fcfae54572b1559a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Task
You need to make the
add
function that has the following behavior:Disclaimer
I don't know where the original task is, I remember seeing it somewhere in Python chat.