Errors
Charles G Waldman
cgw at fnal.gov
Thu Apr 29 18:14:08 EDT 1999
smoothasice at geocities.com writes:
> for word in All_Words:
> z = 0
> while z < len(word):
> if z == 0:
> tally = tally + alpha.index(word[z])
> else:
> tally = tally + (alpha.index(word[z]) * 26)
>
> It gives me this: NameError: tally
> and I don't know why......
Try putting "tally = 0" somewhere. You get a NameError because when
you execute the line
tally = tally + alpha.index(word[z])
for the first time, Python evaluates the right-hand side of the
assignment, and since "tally" has never been assigned to before, it
has no value - it's an undefined name - hence the NameError.
Once you fix this I think you will discover another problem - you need
to increment "z" or else the "while z" loop never terminates.
More information about the Python-list
mailing list