<br><br><div class="gmail_quote">On Thu, Nov 17, 2011 at 2:14 PM, Nidian Job-Smith <span dir="ltr">&lt;<a href="mailto:nidianjs@hotmail.com" target="_blank">nidianjs@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div><div dir="ltr">
<font face="Tahoma" size="2">Hi all,</font><div style="font-family:Tahoma;font-size:10pt"><br></div><div><font face="Tahoma" size="2">I&#39;m new to programming (thus Python), so after reading the basics, I wanted to practise what I&#39;ve learnt . I&#39;ve come across a beginners exercise which is to programme rot13.</font></div>


<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">I&#39;ve written some code but it doesn&#39;t seem to work....</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">Here it is: </font></div>


<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">def rot13(s):</font></div><div><font face="Tahoma" size="2"><div>    char_low = ()</div>


<div>    result = &quot;&quot;</div><div>    if not s.isalpha():</div><div>        return char</div><div>    char_low = char_low.lower()</div><div>    if char_low &lt;= &#39;m&#39;:</div><div>                dist = 13</div>


<div>    else:</div><div>                dist = -13</div><div>    char = chr(ord(char) + dist)</div><div>             </div><div>def rot13_char(ch):</div><div>  return &#39;&#39;.join( rot13(s) for char in ch )</div><div>


  </div><div><br></div><div>Any idea where i&#39;m wrong? </div></font></div></div></div></blockquote></div><br><br>Please, when posting a program that has problems to this list, do not just say that &quot;it doesn&#39;t work&quot;. Tell us what is wrong:<br>


* If you get a syntax error, tell us that, and tell us where it is claimed the syntax error is<br>* if you get an error message, give the error message as well as the stack trace provided with it, or at least the last part of that stack trace<br>


* If the program does not crash, but behaves different from what you expected, tell us what you expected to get, and what you actually got (for example, &quot;After giving the input 5 and 3 I had expected the program to output 8 and ask for a new pair of numbers, but instead it showed 8 lines of 8 stars, printed &#39;Thank you for using my program&#39; and ended.<br>


<br>Having said that, using your program gave me various problems. The first was in <font face="Tahoma" size="2">return &#39;&#39;.join( rot13(s) for char in ch ) - I got an error message that the name &#39;s&#39; was not defined. Reason: the variable before the for should be the same as after, so you should either say &#39;rot13(s) for s in ch&#39; or &#39;rot13(char) for char in ch&#39;<br>


<br>Most of your other problems had the same cause: If you want to use something (a thing, a number, a letter, whatever), use the same name as you used when you defined that thing.<br></font><br clear="all"><br>-- <br>André Engels, <a href="mailto:andreengels@gmail.com" target="_blank">andreengels@gmail.com</a><br>


<br>