<HTML><FONT FACE=arial,helvetica><FONT  SIZE=3 FAMILY="SANSSERIF" FACE="Arial" LANG="0"><BR>
Johnathan H said,<BR>
<BR>
<BLOCKQUOTE TYPE=CITE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"></FONT><FONT  COLOR="#000000" style="BACKGROUND-COLOR: #ffffff" SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">Can anyone help explain them to me?? <BR>
<BR>
This example gives the factorial of a number <BR>
<BR>
def fact(n):<BR>
 r=1<BR>
 while n &gt;0:<BR>
&nbsp;&nbsp; r=r*n<BR>
&nbsp;&nbsp; n=n-1<BR>
 return r <BR>
</BLOCKQUOTE><BR>
</FONT><FONT  COLOR="#000000" style="BACKGROUND-COLOR: #ffffff" SIZE=3 FAMILY="SANSSERIF" FACE="Arial" LANG="0">line code   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Literally spoken   <BR>
</FONT><FONT  COLOR="#000000" style="BACKGROUND-COLOR: #ffffff" SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">1)&nbsp;&nbsp;&nbsp; def fact(n):  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # define a function called fact and let me be<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   # able to set one of the variables called "n"<BR>
2)  &nbsp;&nbsp;&nbsp; r = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; this variable "r" is set to 1 every time we call fact(n) into play&nbsp;  <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>
3)  &nbsp;&nbsp;&nbsp; while n&gt;0: # so long as this statement is true, "n greater than 0" ,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # do the indented lines next, otherwise pass the indented lines <BR>
4)      &nbsp;&nbsp;&nbsp; r=r*n&nbsp;&nbsp; # make my new "r" value equal to my old "r" value times <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #the value of "n", then<BR>
5)      &nbsp;&nbsp;&nbsp; n=n-1&nbsp; # make my new "n" value equal to my old "n" value&nbsp; minus 1<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # then check the while statement again since this is the last <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # indented line of the while block, <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if it's still true then do this block again<BR>
    <BR>
6)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return r   &nbsp;&nbsp; # we reach this statement when n is no longer greater than 0 <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # n must be equal or less than 0<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # so the value that is currently in r gets "return"ed <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # in this case, since you are in the interpreter window, <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this will print the value of r after the function call fact(n)<BR>
&gt;&gt;&gt; fact(5)<BR>
120<BR>
<BR>
which is 5*4*3*2*1 = 120<BR>
<BR>
If we call fact(5), then the first time thru the while loop r = 1 and n = 5<BR>
since n(5) is greater than 0, we get to go to line 4) <BR>
this is where r picks up it's first new value. r = r * n is really 5 = 1 * 5<BR>
But you say how can r have two values? This is not the math I learned in school!<BR>
This statement is really the result of a great short cut for convienience.<BR>
It stems from something like,<BR>
c = b + a<BR>
b = c <BR>
...but please don't think like this!<BR>
r = r * n will make so much sense to you after a while that I ashamed to show you<BR>
that last bit. <BR>
You should try to follow the fact(n) code all the way through, now.<BR>
This will give you great insite as to how the power(x,y=2) works.<BR>
What I will say about that one is that you can call it lots of ways.<BR>
Try power(2), then power(2,3), then power(2,4).... and so on for a hint.<BR>
The "y=2" part is a default value for "y". This means that if you don't give the<BR>
function a "y" value it will always use a 2. <BR>
<BR>
<BR>
Good Luck. Johnathan<BR>
I hope you enjoy programming, Python, and the good folks of the Tutor list.<BR>
Ray St. Marie<BR>
Rastm2@&lt;removethistoreachme&gt;users.sourceforge.net </FONT></HTML>