0
element = {'H': 1, 'N': 6, 'F': 7, 'Cl': 7}
i = input("Enter: ")
dots = '*'
totalDots = (dots * i)

Enter: H

Traceback (most recent call last):
File "D:/Python26/lewisdot.py", line 4, in <module>
i = input("Enter: ")
File "<string>", line 1, in <module>
NameError: name 'H' is not defined


How come?

Thanks

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jimothy
1
element = {'H':1, "N":6, "F":7, 'Cl':7}
i = raw_input('Enter: ')
dots = '*'
totalDots = element[i]*dots
0

hi,
as mentioned in the above post you need to use the raw_input function because input reads in an integer/float value :)

Edited by masterofpuppets: n/a

0

masterofpuppets is right, you have to use input for numbers and raw_input for text strings. If this still doesnt work then try defining the class before putting it in the element list.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.