[Tutor] finding factorials
Payal Rathod
payal-python@staticky.com
Mon Jun 30 03:38:03 2003
Hi,
I am very new to python and programming in general. I was reading a
tutorial "Programming in Python" in which the author has asked the
reader an problem which I am unable to get.
Problem is as follow,
Write a function that implements Euclid's method for finding a common
factor of two numbers. It works like this:
1. You have two numbers, a and b, where a is larger than b
2. You repeat the following until b becomes zero:
1. a is changed to the value of b
2. b is changed to the remainder when a (before the change) is
divided by b (before the change)
3. You then return the last value of a
My very basic solution is going totally wrong,
#!/usr/local/bin/python
def euclid(a,b):
c = a
a = b
b = c % a
if b != 0:
euclid(a,b)
return a
b = 5
euclid(10,5)
print a
It is giving errors. Can someone guide me to a proper solution?
Thanks a lot and hope this basic question is allowed.
Please make a CC to me also.
With warm regards,
-Payal
--
"Visit GNU/Linux Success Stories"
http://payal.staticky.com
Guest-Book Section Updated.