0

Hello,
I am completely stuck on a question I was assigned and was hoping for a little guidance to get me started.

The question is:
Create a program that outputs the molar mass of a molecule. The user will enter a molecule with each atom individually (CO2 would be entered as): C O O
(We are given a file to use) Parse the comma separated text file "elements.csv". The user should continue to be asked for more molecules until they enter a blank line.

I know I have to use dictionaries, keys and values to look them up in the file but I am lost as to how to start this code. Any help would be appreciated.

Thank you

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by KMC
0

Generally you begin with the input

The user will enter a molecule with each atom individually (CO2 would be entered as): C O O...The user should continue to be asked for more molecules until they enter a blank line.

Next would be the dictionary you spoke of, sign-->mass, and looking up each atom so as to add the mass to a total.

Edited by woooee: n/a

0

This is what I've done so far

def main():
    d = {}
    w = raw_input("Atom: ")
    f = open('elements.py.txt', 'r')
    for line in f:
        for word in line.split():
            if word == w:
                d.append(word)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.