3

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) 
wjandrea
  • 28,235
  • 9
  • 60
  • 81
user2168297
  • 31
  • 1
  • 1
  • 2

1 Answers1

6

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 e.g. 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.

Patashu
  • 21,443
  • 3
  • 45
  • 53
  • **Blank lines don't need to be indented.** Most IDEs actually *remove* all trailing whitespace, including in blank lines, and [PEP 8 recommends the same, in my interpretation](/a/61944534/4518341). The only exception is [when pasting code into a Python REPL](/a/2728019/4518341), whitespace in blank lines can be useful. – wjandrea Aug 09 '23 at 17:28