May-03-2022, 10:58 PM
Hello all! So I am starting to mess around with python, it's the first language I am learning, I am also learning independently.
I decided to try and make a program using the periodic table where one can look up any element given either the name, symbol, atomic number or standard atomic weight.
Everything was going pretty well, I won't lie I've got around 4 hours in this code, however for my final elif the program won't use the element.mass() to identify the element.
Instead it returns an error stating AttributeError: 'periodictable' has no attribute 'mass' however I use element.mass in previous parts of the code to print the standard atomic weight so I'm confused.
Any insights? I've included my code below.
I decided to try and make a program using the periodic table where one can look up any element given either the name, symbol, atomic number or standard atomic weight.
Everything was going pretty well, I won't lie I've got around 4 hours in this code, however for my final elif the program won't use the element.mass() to identify the element.
Instead it returns an error stating AttributeError: 'periodictable' has no attribute 'mass' however I use element.mass in previous parts of the code to print the standard atomic weight so I'm confused.
Any insights? I've included my code below.
from periodictable import *
print("Please enter one of the following; \n1:name \n2:symbol \n3:atomic number \n4:Standard Atomic Weight\n")
inquiry = int(input("How will you be searching for elements today? :"))
if inquiry == 1:
print("\nPlease use lowercase letters")
ele_name = input("\nWhat is the name of the element? :")
print("\nSymbol: %s\n\nStandard Atomic Weight: %s\n\nAtomic Number: %s"%(elements.name(ele_name),elements.name(ele_name).mass, elements.name(ele_name).number))
#sys.exit()
elif inquiry == 2:
print("\nRemember to capitalize thr first letter!")
ele_sym = input("\nWhat is the element's symbol? :")
print("\nName: %s \n\nStandard Atomic Weight: %s \n\nAtomic Number: %s"%(elements.symbol(ele_sym).name,elements.symbol(ele_sym).mass,elements.symbol(ele_sym).number))
#sys.exit
elif inquiry == 3:
ele_num = input("\nWhat is the atomic number you're looking for? :")
print("\nSymbol: %s\n\nName: %s\n\nStandard Atomic Weight: %s"% (elements[int(ele_num)],elements[int(ele_num)].name,elements[int(ele_num)].mass))
#sys.exit()
elif inquiry == 4:
SAW = float(input("\nWhat is the element's Standard Atomic Weight? :"))
print("\n%s"%(elements.mass(SAW).name))
