Skip to content

Instantly share code, notes, and snippets.

@zamiur
Created March 7, 2020 06:09
Show Gist options
  • Save zamiur/0f9057a30dd23ba86782744984aa5f96 to your computer and use it in GitHub Desktop.
Save zamiur/0f9057a30dd23ba86782744984aa5f96 to your computer and use it in GitHub Desktop.
Molecular mass calculator. Not Perfect
#!/usr/bin/env python
import getpass # This module is imported only for the purpose of printing out your user
import re
from molmass import *
name = getpass.getuser()
print(f"Hello,{name}") # Prints current username
input = str(input("Please enter in chemical formula: ")) #assign string the chemical formula
if input == "": #If statement to see if user has left input blank
print("You forgot to type in formula")
else:
f = Formula(input) #converts input to "formula"
mf = f.mass #variable assigned to mass of "f"
print(f"your formula is {input}") #prints what user has assigned variable input
print(f"Your total mass is {mf}.") #prints mass of formula
print(f"Below is the composition fo {input}")
print(f.composition())
#TODO: Put some sort of way to restart the program without reopening it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment