<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 12, 2013 at 6:57 AM, RJ Ewing <span dir="ltr"><<a href="mailto:ewing.rj@gmail.com" target="_blank">ewing.rj@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif">I am trying to implement rot 13 and am having troubles. My code is as follows:</div>
<div style="font-family:arial,helvetica,sans-serif">
<br></div><div><div><font face="arial, helvetica, sans-serif">class Rot_13(webapp2.RequestHandler):</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">    </span>def write_form(self, user=""):</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>self.response.out.write(rot_form % user)</font></div><div><span style="white-space:pre-wrap"><font face="arial, helvetica, sans-serif">  </font></span></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">        </span>def get(self):</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">            </span>self.write_form()</font></div>

<div><span style="white-space:pre-wrap"><font face="arial, helvetica, sans-serif">        </font></span></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">  </span>def post(self):</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>user = self.request.get("text")</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">         </span>s = self.rot_text(user)</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>print s</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">           </span>s = "".join(s)</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>self.escape_html(s)</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">               </span>self.write_form(s)</font></div>
</div></div></blockquote><div><br></div><div style>You might want to read up on the translate() method. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div>
<div><span style="white-space:pre-wrap"><font face="arial, helvetica, sans-serif">        </font></span></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">  </span>def rot_text(self, s):</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>ls = [i for i in s]</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">               </span>for i in ls:</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                        </span>if i.isalpha():</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                           </span>if i.isupper():</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                        </span>if i <= 'M':</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                           </span>x = ls.index(i)</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                                </span>ls[ls.index(i)] = chr(ord(i) + 13)</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                        </span>else:</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                                </span>x = ls.index(i)</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                           </span>ls[ls.index(i)] = chr(ord(i) - 13)</font></div>

<div><span style="white-space:pre-wrap"><font face="arial, helvetica, sans-serif">                        </font></span></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                          </span>elif i.islower():</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                        </span>if i <= 'm':</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                           </span>x = ls.index(i)</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                                </span>ls[x] = chr(ord(i) + 13)</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                  </span>elif i > 'm':</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                                </span>x = ls.index(i)</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                                           </span>ls[x] = chr(ord(i) - 13)</font></div>

<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                </span>return ls</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div>
<div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">        </span>def escape_html(self, s):</font></div><div><font face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">         </span>return cgi.escape(s, quote = True)</font></div>

<div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Now if I enter abc, I get nop. But if I enter abcdefghijklmnop, I get abcqrstuvwxyznop. I have included print statements to check if ls[x] is changing and it is, but something is going wrong when I return the ls, and I am not quite sure what it is.</div>

<div style="font-family:arial,helvetica,sans-serif"><br></div></div></div></blockquote><div style>Me neither, how are you calling /returning it? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div style="font-family:arial,helvetica,sans-serif"></div><div style="font-family:arial,helvetica,sans-serif">Thanks </div></div></div>
<br>_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br></div></div>