I've been taking AP Chemistry in my high school this year.
And I've noticed that I'm having to find molar mass of a compound too many times.
So, as I'm wont to do, I coded a line to calculate molar masses for me:
Amu[Com_] :=
Total[
Table[
Com[[i*2]]*ElementData[Com[[i*2 - 1]], "AtomicMass"],
{i, Length[Com]/2}]
]
This code will tell me the molar mass of any compound or element I ask for. For example:
Amu[{"Carbon", 4, "Hydrogen", 10}]
Gives me 58.1222 u.
However, the beauty of mathematica is that a code can almost always be shortened and improved.
So, can anyone think up an improvement to this code?
I'm personally interested in turning my list input to something like C4H10.
Thank you.