<br><br><div class="gmail_quote">On Thu, Nov 17, 2011 at 2:14 PM, Nidian Job-Smith <span dir="ltr"><<a href="mailto:nidianjs@hotmail.com" target="_blank">nidianjs@hotmail.com</a>></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'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I'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've written some code but it doesn'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 = ""</div><div> if not s.isalpha():</div><div> return char</div><div> char_low = char_low.lower()</div><div> if char_low <= 'm':</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 ''.join( rot13(s) for char in ch )</div><div>
</div><div><br></div><div>Any idea where i'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 "it doesn't work". 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, "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 'Thank you for using my program' and ended.<br>
<br>Having said that, using your program gave me various problems. The first was in <font face="Tahoma" size="2">return ''.join( rot13(s) for char in ch ) - I got an error message that the name 's' was not defined. Reason: the variable before the for should be the same as after, so you should either say 'rot13(s) for s in ch' or 'rot13(char) for char in ch'<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>