Inside your function when you say word=word+1, actually the word variable after the equal sign won't be found since you are altering it already in the expression assignee. To overcome this issue there are two solutions, you either use global (which is not recommended) or first try to save the word and digit value in local variables then use them in your expression, see below sample code:
word=0
digit=0
def letter(a):
w = word
d = digit
for each in a:
if each.isalpha():
w=w+1
else:
d=d+1
return w,d
word, digit = letter("Hello123")
print(word,digit)
This could be confusing at start, perhaps you need to read about variable scopes in Python.