Basically I'm trying to make a little program using the periodic table library and I tried to make the first function which returns the mass of the given element.
def mass():
Element = input("Element? ")
return periodictable.Element.mass
But this doesn't work because I'm trying to use a variable instead of an attribute so it says this:
Traceback (most recent call last):
File "<string>", line 424, in run_nodebug
File "<module1>", line 25, in <module>
File "<module1>", line 22, in main
File "<module1>", line 15, in mass
AttributeError: module 'periodictable' has no attribute 'Element'
The correct way to use the mass function with the periodic table should be this:
print(periodictable.H.mass)
print(periodictable.O.mass)
print(periodictable.Na.mass)
So what I'm asking is: can I give an attribute with a variable or do you have any other solution to make the user choose the element?