-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
4

2 に答える 2

9

まあ、リターンは関数の外だからです。

于 2012-11-13T11:27:28.233 に答える
5

このreturnステートメントは、関数定義内でのみ使用できます。例:

def myfunc():
    result = 1
    return result

結果が終了コードである場合は使用するsys.exit(result)か、結果をコンソールに出力する可能性があります。その場合は、を使用してprint(result)ください。

于 2012-11-13T11:38:13.840 に答える