【发布时间】:2012-11-13 11:21:32
【问题描述】:
为什么这给了我错误'return' outside function?
Result = ""
char = ""
# Let char loop over each character in the input string
a = list(s)
for i in range (0, len(s)):
# If this char is a letter:
if (type(a[i])=='str'):
# Set char_low to be char converted to lower case
char_low = a.lower()
print a
# Note: the next 5 lines do not need to be changed -
# they will modify the character as necessary
if char_low <= 'm':
dist = 13
else:
dist = -13
char = chr(ord(char) + dist)
# Push char onto the end of the result
result = result + char
# Return the encrypted text
return result
【问题讨论】:
-
请确保您发布的代码具有正确的缩进(这对 Python 尤其重要...)。代码块必须缩进另外四个空格才能在 Markdown 中呈现为预格式化块,您可以通过选择它然后使用
{}按钮来适当地缩进整个块。
标签: python python-2.7