Hi there! I’m very new to Python and have been asked to modify the following code in a way that it would print 11 instead of 10:
def inc(x):
x = x +1
a = 10
inc(a)
print(a)
The way I understand the code, is that there is no assigned link between variables x
and a
, so the function defined above doesn’t really affect the result when I try to print(a)
.
I’ve tried assigning one variable to the other, but the value for x
(the x+1
) gets overwritten into a
and then 10
, hence printing out 10
again.
I hope someone can help me with this small task and explain to me what way works and why!
Thank you!!