Sorry about the code format in last E-mail. I'll attach the code in notepad, as my e-mail doesnt seem to like sending plain text..
---------------------------------------- > From: nidia...@hotmail.com > To: st...@pearwood.info; tutor@python.org > Date: Thu, 17 Nov 2011 17:45:11 +0000 > Subject: [Tutor] Rot13 > > > Hi all, > > 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 write the code for rot13. > I've written some code but it doesn't seem to work.... > When I run it I get this error: > > > NameError: global name 'rot13_char' is not defined > > > Here it is: > > > > def rot13(s): char_low = () result = "" if not s.isalpha(): > return char char_low = char_low.lower() if char_low <= 'm': > dist = 13 else: dist = -13 char = chr(ord(char) + > dist) def rot13(string): return ''.join( rot13_char(char)for > char in string ) > > > > > Any ideas where i'm wrong? > > Huge thanks, > Nidian > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor
def rot13(s): """ >>> type(rot13("bob")) <type 'str'> >>> len(rot13("foobar")) 6 >>> rot13("abc") 'nop' >>> rot13("XYZ") 'KLM' >>> rot13('5 The Parade') '5 Gur Cnenqr' >>> rot13('5 Gur Cnenqr') '5 The Parade' """ char_low = () result = "" if not s.isalpha(): return char char_low = char_low.lower() if char_low <= 'm': dist = 13 else: dist = -13 char = chr(ord(char) + dist) def rot13(string): return ''.join( rot13_low(char)for char in string )
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor