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

element = {'H':1, "N":6, "F":7, 'Cl':7}
i = raw_input('Enter: ')
dots = '*'
totalDots = element[i]*dots
Member Avatar for masterofpuppets

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.