+ 1

I need help making a program that can take a user given input of a molecular formula and return its molecular mass. Any ideas?

Mainly the program would just have to take the a user input such as C2H6O2 and return its mass. The problem I have is writing a code that can read the user input as there are 2 Cs, 6 Hs, and 2 Os. Any and all help would be greatly appreciated.

22nd Feb 2018, 1:07 AM
Cesar Alcantar
Cesar Alcantar - avatar
3 Answers
+ 2
I think if you want to use all the elements then you need to include the periodic table
1st Mar 2018, 1:15 AM
Vinyas Amin
Vinyas  Amin - avatar
+ 2
Make variables of elements and declare their atomic mass
1st Mar 2018, 1:16 AM
Vinyas Amin
Vinyas  Amin - avatar
0
I'm using python 3. And I considered using 'split', but i couldn't get it to work when the user input was random. For example I ask "input('Enter an equation: ')" And the program needs to be able to automatically calculate the mass depending on whatever the user has decided to input. Limited only to variations of the elements "carbon, oxygen, and hydrogen"
22nd Feb 2018, 2:12 AM
Cesar Alcantar
Cesar Alcantar - avatar