<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="IncrediMail 1.0" name=GENERATOR></HEAD>
<BODY style="BACKGROUND-POSITION: 0px 0px; FONT-SIZE: 12pt; MARGIN: 5px 10px 10px; FONT-FAMILY: Arial" bgColor=#ffffff background="" scroll=yes ORGYPOS="0">
<TABLE id=INCREDIMAINTABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD id=INCREDITEXTREGION style="FONT-SIZE: 12pt; CURSOR: auto; FONT-FAMILY: Arial" width="100%">
<DIV> </DIV>
<DIV> </DIV>
<DIV id=receivestrings>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>From:</B></I> <A href="mailto:dyoo@hkn.eecs.berkeley.edu">Danny Yoo</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Date:</B></I> 02/18/06 15:18:14</DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>To:</B></I> <A href="mailto:kermit@polaris.net">Kermit Rose</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Cc:</B></I> <A href="mailto:tutor@python.org">Tutor</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Subject:</B></I> Re: [Tutor] Need to write a python and call it within a python main program (fwd)</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Just as a note: please use your email client's "Reply to All" feature so</DIV>
<DIV>that our correspondence stays on the Python-tutor mailing list. The idea</DIV>
<DIV>is that if I say something that is inaccurate or incomplete, the other</DIV>
<DIV>helpers can come and compensate for my weaknesses.</DIV>
<DIV> </DIV>
<DIV> *********</DIV>
<DIV> </DIV>
<DIV>ok</DIV>
<DIV> </DIV>
<DIV>***************</DIV>
<DIV>> ***************</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Python has a familiar control-flow syntax for branches in the 'if'</DIV>
<DIV>statement. For example, here is an interactive session that shows how one</DIV>
<DIV>can use it for a simple case-analysis:</DIV>
<DIV> </DIV>
<DIV>######</DIV>
<DIV>>>> def is_even(n):</DIV>
<DIV>.... if n % 2 == 0: ## % is the modulo operator</DIV>
<DIV>.... return "yes"</DIV>
<DIV>.... else:</DIV>
<DIV>.... return "no"</DIV>
<DIV>....</DIV>
<DIV>>>> is_even(42)</DIV>
<DIV>'yes'</DIV>
<DIV>>>> is_even(13)</DIV>
<DIV>'no'</DIV>
<DIV>######</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>******</DIV>
<DIV> </DIV>
<DIV>This is a very good example.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Using it, I translate my pseudo code</DIV>
<DIV> </DIV>
<DIV>set j = 8 * mod(a,2) + 4 * mod(b,2) + 2 * mod(c,2) + mod(d,2)</DIV>
<DIV> </DIV>
<DIV>if j = 0, a,b,c,d = a/2,b/2,c/2,d/2<BR>if j = 1, a,b,c,d = -1,-1,-1,-1<BR>if j = 2, a,b,c,d = a,b/2,c,d/2<BR>if j = 3, a,b,c,d = a,(a+b)/2,c,(d-c)/2<BR>if j = 4, a,b,c,d = a,b,c/2,d/2<BR>if j = 5, a,b,c,d = a,b,(a+c)/2,(d-b)/2<BR>if j = 6, a,b,c,d = b,a,d,c<BR>if j = 7, a,b,c,d = b,a,d,c<BR>if j = 8, a,b,c,d = -1,-1,-1,-1<BR>if j = 9, a,b,c,d = 2*a,a+b,a+c,(d-a-b-c)/2<BR>if j = 10, a,b,c,d = b,a,d,c<BR>if j = 11, a,b,c,d = 2*a,a+b,c,(d-c)/2<BR>if j = 12, a,b,c,d = b,a,d,c<BR>if j = 13, a,b,c,d = 2*a,b,a+c,(d-b)/2<BR>if j = 14, a,b,c,d = b,a,d,c<BR>if j = 15, a,b,c,d = a,a+b,a+c,d-a-b-c</DIV>
<DIV> </DIV>
<DIV><BR>into</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>>>> def trans01(a,b,c,d):<BR>.... j = 8 * a%2 + 4 * b%2 + 2 * c%2 + d%2<BR>.... if j = 0, a,b,c,d = a/2,b/2,c/2,d/2<BR>.... if j = 1, a,b,c,d = -1,-1,-1,-1<BR>.... if j = 2, a,b,c,d = a,b/2,c,d/2<BR>.... if j = 3, a,b,c,d = a,(a+b)/2,c,(d-c)/2<BR>.... if j = 4, a,b,c,d = a,b,c/2,d/2<BR>.... if j = 5, a,b,c,d = a,b,(a+c)/2,(d-b)/2<BR>.... if j = 6, a,b,c,d = b,a,d,c<BR>.... if j = 7, a,b,c,d = b,a,d,c<BR>.... if j = 8, a,b,c,d = -1,-1,-1,-1<BR>.... if j = 9, a,b,c,d = 2*a,a+b,a+c,(d-a-b-c)/2<BR>.... if j = 10, a,b,c,d = b,a,d,c<BR>.... if j = 11, a,b,c,d = 2*a,a+b,c,(d-c)/2<BR>.... if j = 12, a,b,c,d = b,a,d,c<BR>.... if j = 13, a,b,c,d = 2*a,b,a+c,(d-b)/2<BR>.... if j = 14, a,b,c,d = b,a,d,c<BR>.... if j = 15, a,b,c,d = a,a+b,a+c,d-a-b-c<BR>IndentationError: expected an indented block (<pyshell#0>, line 2)<BR>>>> <BR>>>> <BR>>>> <BR>
<DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Why did I get this error message? </DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></DIV>
<DIV> </DIV>
<DIV>Kermit < <A href="mailto:kermit@polaris.net">kermit@polaris.net</A> ></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></TD></TR>
<TR>
<TD id=INCREDIFOOTER width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD width="100%"></TD>
<TD id=INCREDISOUND vAlign=bottom align=middle></TD>
<TD id=INCREDIANIM vAlign=bottom align=middle></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>