[Tutor] Doctest error!
John
nidianjs at hotmail.com
Fri Nov 18 16:29:34 CET 2011
Hi all,
When i run a doctest on this piece of code (shown at bottom) i get this error message [from the doctest]:
Trying:
rot13('5 The Parade')
Expecting:
'5 Gur Cnenqr'
**********************************************************************
File "F:\Uni\Rot13_1.py", line 12, in Rot13_1.rot13
Failed example:
rot13('5 The Parade')
Expected:
'5 Gur Cnenqr'
Got:
'B-aur-]n\x7fnqr'
Trying:
rot13('5 Gur Cnenqr')
Expecting:
'5 The Parade'
**********************************************************************
File "F:\Uni\Rot13_1.py", line 14, in Rot13_1.rot13
Failed example:
rot13('5 Gur Cnenqr')
Expected:
'5 The Parade'
Got:
'B-T\x82\x7f-P{r{~\x7f'
An one have any idea why? (I'm guessing its to do with the numbers)
code:
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'
"""
result = '' # initialize output to empty
for char in s: # iterate over string
if int:
char_low = s.lower()
if char_low<= 'm':
dist = 13
else:
dist = -13
char = chr(ord(char) + dist)
result+=char
return result
More information about the Tutor
mailing list