+ 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.
3 odpowiedzi
+ 2
I think if you want to use all the elements then you need to include the periodic table
+ 2
Make variables of elements and declare their atomic mass
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"