[Tutor] name is not defined error

Kristinn Didriksson kdidriksson at gmail.com
Sun Oct 29 17:30:57 CET 2006


Hello,
I am new to Python and programming and going through the "Python  
Programming " book by Zelle.
I am trying to solve the following exercise and get a name is not  
defined error. It is my understanding that eval turns a string into a  
number and then I can do math operations on it.
Any help is greatly appreciated.
Regards,
Kristinn

I input Kristinn at the prompt and this is the error message:
------------------
Please enter your name: Kristinn
Traceback (most recent call last):
   File "/Users/krissd/Desktop/python/code_zelle/chapter3/6.py", line  
18, in <module>
     main()
   File "/Users/krissd/Desktop/python/code_zelle/chapter3/6.py", line  
12, in main
     numEquiv = eval(eachLetter)
   File "<string>", line 1, in <module>
NameError: name 'k' is not defined
----------------------
This is the program code:
-------------------
# Numerology. Calculate the numeric value of a name. a =1, b=1,...z = 26
# Add the values for each letter for a total.

def main():
	
	import string
	print "This program  calculates the numeric value of your name for  
divination."
	name = raw_input("Please enter your name: ")
	
	totalValue = 0
	for eachLetter in string.lower(name):
		numEquiv = eval(eachLetter)
		letterValue = numEquiv -96
		totalValue = totalValue + numEquiv
		
	print "The total numerical value of your name is " + totalValue +"!"
	
main()
-------------------


More information about the Tutor mailing list