On Tue, Mar 12, 2013 at 6:57 AM, RJ Ewing <ewing...@gmail.com> wrote:
> I am trying to implement rot 13 and am having troubles. My code is as > follows: > > class Rot_13(webapp2.RequestHandler): > def write_form(self, user=""): > self.response.out.write(rot_form % user) > def get(self): > self.write_form() > def post(self): > user = self.request.get("text") > s = self.rot_text(user) > print s > s = "".join(s) > self.escape_html(s) > self.write_form(s) > You might want to read up on the translate() method. > def rot_text(self, s): > ls = [i for i in s] > for i in ls: > if i.isalpha(): > if i.isupper(): > if i <= 'M': > x = ls.index(i) > ls[ls.index(i)] = chr(ord(i) + 13) > else: > x = ls.index(i) > ls[ls.index(i)] = chr(ord(i) - 13) > elif i.islower(): > if i <= 'm': > x = ls.index(i) > ls[x] = chr(ord(i) + 13) > elif i > 'm': > x = ls.index(i) > ls[x] = chr(ord(i) - 13) > return ls > > def escape_html(self, s): > return cgi.escape(s, quote = True) > > 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. > > Me neither, how are you calling /returning it? > Thanks > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor