wasm-demo/demo/ermis-f/python_m/cur/0603

39 lines
1.0 KiB
Plaintext

From: cgw at fnal.gov (Charles G Waldman)
Date: Thu, 29 Apr 1999 22:14:08 GMT
Subject: Errors
In-Reply-To: <3728CD26.907ED9A1@geocities.com>
References: <3728CD26.907ED9A1@geocities.com>
Message-ID: <14120.55728.975548.357835@buffalo.fnal.gov>
X-UID: 603
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.