Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculator():
- result = 0
- def add(x):
- nonlocal result
- result += x
- def multiply(x):
- nonlocal result
- result *= x
- def get_result():
- return result
- return (add, multiply, get_result)
- (add, multiply, get_result) = calculator()
- (add1, multiply2, get_result2) = calculator()
- add(1)
- add(2)
- multiply(2)
- print(get_result())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement