I have been looking for methods for using the value from a str input, where some of the values (of the str) are keys to a dictionary I have. And then calculate with the values the keys have. It's hard to explain, but here is the example:
I have a dictionary for each element of the periodic table (each dictionary contains the mass of the element with the key "Atomic weight" (H has the mass 1.008u.)
I want to calculate the molecular mass when the input string is for example: "H*2+O" which is H20 (18u)
Here is what I have at the moment:
molecularmass = str(input("Write which molecular mass you want f.example: H*2+O this is H2O (water): "))
for sym in element.keys():
if element[sym]["Sym"] in molecularmass:
print(element[sym]["Sym"])
molecularmass.replace(element[sym]["Sym"], str(element[sym]["Atomic weight"]))