PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# challenge Python from SL that I think a bit difficult
# to achieve it in ten seconds
def f(a, x):
# This function returns the sum of a.x and x
return a.x + x
class A:
def f(self, x):
# This method sets the instance's x attribute and returns x + 1
self.x = x
return x + 1
# Create an instance of A class
a = A()
# Call the instance method f
# i.e. a.f(2) which sets a.x to 2 precisely on line 11:
# self.x = x --> 2 on first parameter of f function named a so f(2, a.f(2))
# and returns 3 cause of return x + 1
y = f(a, a.f(2))
# Print the result should be 5
print(y)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run