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
Re: [Tutor] finding factorials
by Gregor Lingl other posts by this author
Jul 1 2003 7:12PM messages near this date
Re: [Tutor] finding factorials | Re: [Tutor] finding factorials
Payal Rathod schrieb:

Hello Payal! I think I should have made some comments on your comments --

> 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?
> 
#- this will return the gcd of b and the rest when a is divided by b

>         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. 
> 
#-- I tried it out and it - not surprisingly - worked!

> 
> 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.
>   
> 
#-- These remain 100 and 20 respectively, because your code doesn't contain
#-- statements, which change the values of x and y.
#--  Only the values of a and b (and c) are changed, but these are 
entirely different
#-- variables, local to the function euclid and not globally visible. 
The change of
#-- their values is revealed by your print-statements.

> print result
> 
> # The result is given as 20 which I think is wrong. 
> 
#-- Why do you think this is wrong? What do you think is the greatest
#-- common divisor of 100 and 20?

> # Is there anything 
> # wrong with my mathematical logic or my function?
>   
> 
#-- Hmm ??? See my previous posting.

Best wishes, Gregor

> With warm regards,
> -Payal
> 
> 
>   
> 





_______________________________________________
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