[Tutor] finding factorials

Payal Rathod payal-python@staticky.com
Mon Jun 30 22:40:02 2003


On Mon, Jun 30, 2003 at 10:33:36AM -0700, Danny Yoo wrote:
> Same mistake as last time.  *grin* The code is simply dropping the value
> that you're calculating from doing euclid().  We need to capture that
> value:

Sorry Danny I am still not getting it. Now I am so confused that I think
I don't know what exactly a function does and what is it it returns.

I have posted my code below with some comments regarding issues I don't
get.

#!/usr/local/bin/python

def euclid(a,b):
        while b != 0:
                c = a
                a = b
                b = c % a
                print 'A = ', a
                print 'B = ', b
                return euclid(a,b)
# What will this return exactly?
        else:
                return a

x = 100
y = 20

result = euclid(x, y)

# Why do we define x and y here seperately?
# Can't we have result = euclid(100,20)
# This apparently is not working. 

print x
print y

# This always prints 100 and 20. I think it should print the present values
# of x and y which are not 100 and 20 always.

print result

# The result is given as 20 which I think is wrong. Is there anything 
# wrong with my mathematical logic or my function?

With warm regards,
-Payal


-- 
"Visit GNU/Linux Success Stories"
http://payal.staticky.com
Guest-Book Section Updated.