BEE*_*BEE -6 python python-2.7
为什么这会给我错误'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
Run Code Online (Sandbox Code Playgroud)
该return语句只能在函数定义中使用,例如:
def myfunc():
result = 1
return result
Run Code Online (Sandbox Code Playgroud)
sys.exit(result)如果结果是退出代码,您可能要么使用,或者更有可能将结果打印到控制台,在这种情况下只需使用print(result).
| 归档时间: |
|
| 查看次数: |
1032 次 |
| 最近记录: |