[Tutor] finding factorials - hmm..., gcd
Payal Rathod
payal-python@staticky.com
Tue Jul 1 23:18:09 2003
On Tue, Jul 01, 2003 at 09:51:05PM +0200, Gregor Lingl wrote:
Thanks for the mails all of you and thanks for the "magic" example.
Please clear my doubt below.
Commented example below. Print statements are now numbered.
print "WHAT'S GOING ON?"
x =4
y=10
z = 0
print "x =",x,"y =",y,"z =",z # -------> (1)
def look(a,b):
print "x =",x,"y =",y,"z =",z,"a =",a,"b =",b # --------> (2)
a=2*a
b=2*b
c=a*b
print "x =",x,"y =",y,"z =",z,"a =",a,"b =",b,"c =",c # ------> (3)
return c
c = c*c # ;-)
print "x =",x,"y =",y,"z =",z,"a =",a,"b =",b,"c =",c # -----> (4)
print "x =",x,"y =",y,"z =",z # ------------> (5)
z = look(x,y) # this will execute 2 (!) print-statements
# you won't be able to print a,b,c here
print "x =",x,"y =",y,"z =",z # ---------> (6)
The output is,
WHAT'S GOING ON?
x = 4 y = 10 z = 0 # This comes from print statement (1)
x = 4 y = 10 z = 0 # This comes from print statement (5)
x = 4 y = 10 z = 0 a = 4 b = 10
# Where the world this comes from? a and b are never defined anywhere,
# nor are they assigned values of x and y. Where did python get the
# idea that a = 4 and b = 10?
x = 4 y = 10 z = 0 a = 8 b = 20 c = 160
x = 4 y = 10 z = 160
# Once the above question is answered I think this will have the same
# logic.
Thanks a lot for this "magic" example.
With warm regards,
-Payal
--
"Visit GNU/Linux Success Stories"
http://payal.staticky.com
Guest-Book Section Updated.