please, can someone help me with the code bellow? When I run it the logs said:
return method(*args, **kwargs)
File \"C:\\Users\\CG\\Documents\\udacity\\ro
It's probably because the text is being entered as unicode:
>>> def rot13(st):
... import string
... tab1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
... tab2 = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
... tab = string.maketrans(tab1, tab2)
... return st.translate(tab)
...
>>> rot13('test')
'grfg'
>>> rot13(u'test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in rot13
TypeError: character mapping must return integer, None or unicode
>>>
This question covers what you need:
If you are sure that unicode strings aren't important I guess you could just:
return str(st).translate(tab)