0
How do I print 6 and 5? ( python )
x = 0 y = 0 def incr(x): y = x + 1 return y print (incr(5),y)
6 odpowiedzi
+ 3
Because you call the function square() twice and each time the variable numcalls is increased by 1 😏
+ 3
y = 0
def incr(x):
global y
y = x
return y + 1
print (incr(5), y)
+ 3
you can learn in this way, kokito,
You can put the code in code playground
And add print (.. Variables...) in between the lines inside your function,
And then you can see how the variable are changed during the process.
It is quicker and more fun to find out yourself😉
+ 1
thank u
0
numcalls = 0
def square(x):
global numcalls
numcalls = numcalls + 1
return x * x
print (square(5))
print (square(2*5))
print(numcalls)
0
why print numcalls 2?