简体   繁体   中英

expected an intended block in Python

I am totally a green hand, I don't know what's wrong with my code. I tried to adjust it several times but it didn't work and kept alerting expected an intended block when I run the code.

def abc(words_list):

number1 = 0
number2 = 0

for L in words_list:
    if L[0] in 'aeiou':
        number1 = number1 + 1

    else:
        number2 = number2 + 1
        first_char = L[0]

        for i in range(1,len[L]):
            L[i-1] = L[i]
        L[-1] = first_char
    L = L + 'ay'

return(number1, number2) 

After the start of a function ( def ), you need to indent your code once. As in:

def abc(words_list):


    number1 = 0
    number2 = 0

    for L in words_list:
        if L[0] in 'aeiou':
            number1 = number1 + 1

        else:
            number2 = number2 + 1
            first_char = L[0]

            for i in range(1,len[L]):
                L[i-1] = L[i]
            L[-1] = first_char
        L = L + 'ay'

    return(number1, number2) 

In addition, any blank lines need to have the correct indentation. When copying-pasting eg to and from stack overflow you may lose the indentation of spaces, but python considers them important too. For example, the two blank lines after def need to be at the same indentation as the line starting number1 .

Programs such as notepad++ will allow you to see how indented blank lines are, and any good python IDE should work too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM