[Tutor] Rot13

Nidian Job-Smith nidianjs at hotmail.com
Thu Nov 17 18:45:11 CET 2011


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 		 	   		  


More information about the Tutor mailing list