Why is “i” outside the function?
You’re using ‘i’ as the temporary variable in the for loop and as the counter of letters in the word paramter. Wouldn’t it be better to call “i” something like “counter” or “sum” (?) (b/c you’re counting the letters in a word and you’re returning the total count
Remove the output = part before the print()
When you call the function, you should be able to pass through any string (as an argument) and the function logic should calculate the count of letters in the string. I hope that makes sense(?)
for (temporary variable) in (list variable): (action)
You’re using “sum” as the temp var in the for loop and as the counter of the letters in the string. They are two different types (the link I posted above).
What if you wrote something like this:
def get_length(word):
sum = 0
for i in word:
sum += 1
return sum
print(get_length("avocado"))
If you happen to use Google’s Colab, you can search for your error from the notebook itself (or, you could just use Google and search for your error too: