How do I print 6 and 5? ( python ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

20th Dec 2018, 4:32 PM
kokito
6 Answers
+ 3
Because you call the function square() twice and each time the variable numcalls is increased by 1 😏
20th Dec 2018, 5:07 PM
Anna
Anna - avatar
+ 3
y = 0 def incr(x): global y y = x return y + 1 print (incr(5), y)
20th Dec 2018, 4:52 PM
Anna
Anna - avatar
+ 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😉
20th Dec 2018, 6:40 PM
Gordon
Gordon - avatar
+ 1
thank u
20th Dec 2018, 4:58 PM
kokito
0
numcalls = 0 def square(x): global numcalls numcalls = numcalls + 1 return x * x print (square(5)) print (square(2*5)) print(numcalls)
20th Dec 2018, 5:05 PM
kokito
0
why print numcalls 2?
20th Dec 2018, 5:05 PM
kokito