expected an intended block in Python
13,197
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.
Related videos on Youtube
Author by
user2168297
Updated on June 12, 2022Comments
-
user2168297 over 1 year
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)