ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
[Tutor] finding factorials
by Payal Rathod other posts by this author
Jun 30 2003 7:31AM messages near this date
RE: [Tutor] Function Programming Style | Re: [Tutor] finding factorials
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.

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Payal Rathod
lonetwin
Kristoffer Erlandsson
Payal Rathod
Gregor Lingl
Danny Yoo
Payal Rathod
Danny Yoo
Gregor Lingl
Danny Yoo

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved