Inspiration

I have always wanted a program to give me answers to my chemistry homework. For my final project in my computer science class, I am building a package that will do just that, saving me time on homework.

What it does

So far it can index chemicals and get their weight as well as add two together to get their weight.

How I built it

The parser looks like this:

def __init__(self):
        self.symbols = []
        self.masses = []
        self.chemicals = {}
        response = requests.get('https://www.ptable.com/') #get data with an http request
        html_doc = response.text
        soup = BeautifulSoup(html_doc, "html.parser")
        for e in soup.select('tbody td'):
            p = e.find('acronym')
            if p != None:
                if p.text != "Symbol" and p.text not in self.symbols:
                    self.symbols.append(p.text)
        for mass in soup.select('tbody td'):
                mass = mass.find('i')
                if mass != None:
                    if mass.text != "Weight":
                        number = mass.text
                        if "(" in mass.text and ")" in mass.text:
                            number = mass.text[1:-1]
                        self.masses.append(number)
        idx = 0
        for element in self.symbols:
            self.chemicals[element] = self.masses[idx]
            idx += 1

Challenges I ran into

I was not comfortable in CSS or BeautifulSoup so I really had to push myself to try and parse the information that I needed.

Accomplishments that I'm proud of

I can now find elements and their weight and am starting a scientific calculator. It was very difficult for me, but I ultimately succeeded in the hardest part.

What I learned

That ultamitely, the hard work pays off and once you get through the hardest part, it's all smooth sailing.

What's next for final-project-chemistry

I plan on expanding it to work with compounds and balancing equations. This project was started recently so I am trying my best to get everything done.

Share this project:

Updates