Created
March 17, 2021 14:02
-
-
Save smith0022/dd029bb35f06d9e6a6886301d45798f4 to your computer and use it in GitHub Desktop.
CHEMISTRY MOLARITY MOLALITY MOLE FRACTION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Elements = {'H': 1, 'He': 4, 'Li': 7, 'Be': 9, 'B': 10.811, 'C': 12, 'N': 14, | |
'O': 16, 'F': 18.9984032, 'Ne': 20.1797, 'Na': 22.98976928, 'Mg': 24.305, 'Al': 26.9815386, | |
'Si': 28.0855, 'P': 30.973762, 'S': 32.065, 'Cl': 35.453, 'Ar': 39.948, 'K': 39.0983, 'Ca': 40.078, | |
'Sc': 44.955912, 'Ti': 47.867, 'V': 50.9415, 'Cr': 51.9961, 'Mn': 54.938045, | |
'Fe': 55.845, 'Co': 58.933195, 'Ni': 58.6934, 'Cu': 63.546, 'Zn': 65.409, 'Ga': 69.723, 'Ge': 72.64, | |
'As': 74.9216, 'Se': 78.96, 'Br': 79.904, 'Kr': 83.798, 'Rb': 85.4678, 'Sr': 87.62, 'Y': 88.90585, | |
'Zr': 91.224, 'Nb': 92.90638, 'Mo': 95.94, 'Tc': 98.9063, 'Ru': 101.07, 'Rh': 102.9055, 'Pd': 106.42, | |
'Ag': 107.8682, 'Cd': 112.411, 'In': 114.818, 'Sn': 118.71, 'Sb': 121.760, 'Te': 127.6, | |
'I': 126.90447, 'Xe': 131.293, 'Cs': 132.9054519, 'Ba': 137.327, 'La': 138.90547, 'Ce': 140.116, | |
'Pr': 140.90465, 'Nd': 144.242, 'Pm': 146.9151, 'Sm': 150.36, 'Eu': 151.964, 'Gd': 157.25, | |
'Tb': 158.92535, 'Dy': 162.5, 'Ho': 164.93032, 'Er': 167.259, 'Tm': 168.93421, 'Yb': 173.04, | |
'Lu': 174.967, 'Hf': 178.49, 'Ta': 180.9479, 'W': 183.84, 'Re': 186.207, 'Os': 190.23, 'Ir': 192.217, | |
'Pt': 195.084, 'Au': 196.966569, 'Hg': 200.59, 'Tl': 204.3833, 'Pb': 207.2, 'Bi': 208.9804, | |
'Po': 208.9824, 'At': 209.9871, 'Rn': 222.0176, 'Fr': 223.0197, 'Ra': 226.0254, 'Ac': 227.0278, | |
'Th': 232.03806, 'Pa': 231.03588, 'U': 238.02891, 'Np': 237.0482, 'Pu': 244.0642, 'Am': 243.0614, | |
'Cm': 247.0703, 'Bk': 247.0703, 'Cf': 251.0796, 'Es': 252.0829, 'Fm': 257.0951, 'Md': 258.0951, | |
'No': 259.1009, 'Lr': 262, 'Rf': 267, 'Db': 268, 'Sg': 271, 'Bh': 270, 'Hs': 269, 'Mt': 278, | |
'Ds': 281, 'Rg': 281, 'Cn': 285, 'Nh': 284, 'Fl': 289, 'Mc': 289, 'Lv': 292, 'Ts': 294, 'Og': 294, | |
'ZERO': 0} | |
def molar_mass_formula(solute,molar_mass): | |
for x in solute: | |
k = 0 | |
j = "" | |
for y in x: | |
if y.isalpha(): | |
j = j + y | |
elif y.isdigit(): | |
k = k + int(y) | |
break | |
else: | |
k = 1 | |
molar_mass += Elements[j] * k | |
return molar_mass | |
def mass_percentage(mass_of_solute,mass_of_solution): | |
try: | |
mass_per = (mass_of_solute / mass_of_solution) * 100 | |
except: | |
try: | |
mass_of_solute = float(input("mass of solute: ")) | |
mass_of_solution = float(input("total mass of the solution: ")) | |
mass_per=(mass_of_solute/mass_of_solution)*100 | |
except : | |
mass_per=float(input("mass percentage: ")) | |
try: | |
mass_of_solution = (mass_of_solute / mass_per) * 100 | |
except : | |
mass_of_solution = float(input("total mass of the solution: ")) | |
mass_of_solute = (mass_per * mass_of_solution) / 100 | |
finally: | |
print("total mass of the solution :",mass_of_solution) | |
print("mass of the solute :", mass_of_solute) | |
print("mass percentage of solution :", mass_per,"%") | |
return (mass_of_solute,mass_of_solution) | |
def volume_percentage(): | |
try: | |
volume_of_solute = float(input("volume of solute: ")) | |
total_volume_of_solution = float(input("total volume of the solution: ")) | |
volume_per=(volume_of_solute/total_volume_of_solution)*100 | |
except : | |
volume_per=float(input("volume percentage: ")) | |
try: | |
total_volume_of_solution = (volume_of_solute / volume_per) * 100 | |
except : | |
total_volume_of_solution = float(input("total mass of the solution: ")) | |
volume_of_solute = (volume_per * total_volume_of_solution) / 100 | |
finally: | |
print("total volume of the solution :",total_volume_of_solution) | |
print("volume of the solute :", volume_of_solute) | |
print("volume percentage of solution :", volume_per,"%") | |
return total_volume_of_solution | |
def mass_by_volume_percentage(mass_of_solute,total_volume_of_solution): | |
try: | |
mass_of_solute = float(input("mass of solute : ")) | |
total_volume_of_solution = float(input("total volume of the solution: ")) | |
mass_by_volume_per=(mass_of_solute/total_volume_of_solution)*100 | |
except : | |
mass_by_volume_per=float(input("volume percentage: ")) | |
try: | |
total_volume_of_solution = (mass_of_solute / mass_by_volume_per) * 100 | |
except : | |
total_volume_of_solution = float(input("total mass of the solution: ")) | |
mass_of_solute = (mass_by_volume_per * total_volume_of_solution) / 100 | |
finally: | |
print("total volume of the solution :",total_volume_of_solution) | |
print("volume of the solute :", mass_of_solute) | |
print("volume percentage of solution :", mass_by_volume_per,"%") | |
return (mass_of_solute,total_volume_of_solution) | |
def ppm(mass_of_solute,mass_of_solution): | |
try: | |
PPM = (mass_of_solute / mass_of_solution) * 1000000 | |
except: | |
try: | |
mass_of_solute = float(input("mass of solute: ")) | |
mass_of_solution = float(input("total mass of the solution: ")) | |
PPM=(mass_of_solute/mass_of_solution)*1000000 | |
except : | |
PPM=float(input("mass percentage: ")) | |
try: | |
mass_of_solution = (mass_of_solute / PPM) * 1000000 | |
except : | |
mass_of_solution = float(input("total mass of the solution: ")) | |
mass_of_solute = (PPM * mass_of_solution) / 1000000 | |
finally: | |
print("total mass of the solution :",mass_of_solution) | |
print("mass of the solute :", mass_of_solute) | |
print("PARTS PER MILLION :", PPM) | |
return (mass_of_solute,mass_of_solution) | |
def molarity(mass_of_solute,molar_mass,mass_of_solution): | |
try: | |
moles_of_solute=mass_of_solute/molar_mass | |
volume_of_solution_in_litre=float(input("enter the volume of solution in litres :")) | |
molarity=moles_of_solute/volume_of_solution_in_litre | |
except: | |
try: | |
mass_of_solute=float(input("enter the mass")) | |
volume_of_solution_in_litre = float(input("enter the volume of solution in litres :")) | |
moles_of_solute=mass_of_solute/molar_mass | |
molarity=moles_of_solute/volume_of_solution_in_litre | |
print(molarity) | |
except: | |
try: | |
volume_of_solution_in_litre = float(input("enter the volume of solution in litres :")) | |
molarity=float(input("enter the molarity:")) | |
moles_of_solute = molarity * volume_of_solution_in_litre | |
mass_of_solute = moles_of_solute * molar_mass | |
print("mass of the solute",mass_of_solute) | |
except: | |
try: | |
try: | |
moles_of_solute=float(input("enter the number of moles:")) | |
volume_of_solution_in_litre=molarity/moles_of_solute | |
except: | |
molarity = float(input("enter the molarity:")) | |
moles_of_solute=mass_of_solute/molar_mass | |
volume_of_solution_in_litre=molarity/moles_of_solute | |
except: | |
try: | |
density = float(input("enter the density:")) | |
volume_of_solution_in_litre = mass_of_solution / density | |
moles_of_solute = mass_of_solute / molar_mass | |
molarity = moles_of_solute / volume_of_solution_in_litre | |
except: | |
density = float(input("enter the density:")) | |
mass_of_solution = float(input("enter the density:")) | |
volume_of_solution_in_litre = mass_of_solution / density | |
molarity = moles_of_solute / volume_of_solution_in_litre | |
finally: | |
print("the molarity =",molarity) | |
print("volume of solution =",volume_of_solution_in_litre) | |
print("moles of solution =",moles_of_solute) | |
return (mass_of_solute,molar_mass,mass_of_solution) | |
def molality(mass_of_solute,molar_mass,mass_of_solution): | |
try: | |
moles_of_solute=mass_of_solute/molar_mass | |
molality=moles_of_solute / (mass_of_solution-mass_of_solute) | |
mass_of_solvent = mass_of_solution - mass_of_solute | |
except: | |
try: | |
moles_of_solute=mass_of_solute/molar_mass | |
molality = moles_of_solute / (mass_of_solution-mass_of_solute) | |
mass_of_solvent=mass_of_solution-mass_of_solute | |
except: | |
try: | |
mass_of_solute = float(input("enter the mass of solute :")) | |
moles_of_solute = mass_of_solute / molar_mass | |
molality = moles_of_solute / (mass_of_solution-mass_of_solute) | |
mass_of_solvent = mass_of_solution - mass_of_solute | |
except: | |
try: | |
molality=float(input("enter the molality:")) | |
mass_of_solvent=moles_of_solute/molality | |
except: | |
mass_of_solvent=float(input("enter the mass of solvent:")) | |
moles_of_solute=molality*mass_of_solvent | |
mass_of_solute=moles_of_solute*molar_mass | |
print("mass of solute :",mass_of_solute) | |
finally: | |
print("the molality =", molality) | |
print("mass of solvent =", mass_of_solvent) | |
print("moles of solution =", moles_of_solute) | |
return (mass_of_solute,molar_mass,mass_of_solution) | |
def mole_fraction(mass_of_solute,mass_of_solution,molar_mass,molar_mass_solvent): | |
try: | |
moles_of_solute = mass_of_solute/molar_mass | |
mass_of_solvent = mass_of_solution-mass_of_solute | |
moles_of_solvent = mass_of_solvent / molar_mass_solvent | |
total_moles=moles_of_solute+moles_of_solvent | |
mole_fraction_of_solute=moles_of_solute / total_moles | |
mole_fraction_of_solvent=moles_of_solvent / total_moles | |
except: | |
try: | |
mass_of_solvent=float(input("enter the mass of solvent :")) | |
moles_of_solute = mass_of_solute / molar_mass | |
moles_of_solvent = mass_of_solvent / molar_mass_solvent | |
total_moles = moles_of_solute + moles_of_solvent | |
mole_fraction_of_solute = moles_of_solute / total_moles | |
mole_fraction_of_solvent = moles_of_solvent / total_moles | |
except: | |
mass_of_solute = float(input("enter the mass of solute :")) | |
moles_of_solute = mass_of_solute / molar_mass | |
moles_of_solvent = mass_of_solvent / molar_mass_solvent | |
total_moles = moles_of_solute + moles_of_solvent | |
mole_fraction_of_solute = moles_of_solute / total_moles | |
mole_fraction_of_solvent = moles_of_solvent / total_moles | |
finally: | |
print("mole fraction of solute :",mole_fraction_of_solute) | |
print("mole fraction of solvent :", mole_fraction_of_solvent) | |
return (mass_of_solute,mass_of_solute+mass_of_solvent) | |
print("please input the formula as shown in given example:") | |
print("'H2O' should be written as 'H2 O'") | |
solute = input("enter the formula of solute : ") | |
#mass = int(input("enter the given mass : ")) | |
solute=solute.split() | |
solvent=input('enter the formula of solvent :') | |
solvent=solvent.split() | |
mass_of_solute="" | |
mass_of_solution="" | |
moles_of_solute="" | |
molar_mass = molar_mass_formula(solute, 0) | |
molar_mass_solvent = molar_mass_formula(solvent, 0) | |
while True: | |
print("you can find :") | |
print("""1 .mass_percentage | |
2 .volume percentage | |
3 .mass by volume percentage | |
4 .ppm | |
5 .molarity | |
6 .molality | |
7 .mole fraction | |
8 for quiting""") | |
pro=int(input("entre the number :")) | |
if pro==1: | |
mass_of_solute,mass_of_solution=mass_percentage(mass_of_solute,mass_of_solution) | |
elif pro==2: | |
volume_of_solution=volume_percentage(volume_of_solution) | |
elif pro==3: | |
mass_of_solute,volume_of_solution=mass_by_volume_percentage(mass_of_solute,volume_of_solution) | |
elif pro == 4: | |
mass_of_solute, mass_of_solution=ppm(mass_of_solute, mass_of_solution) | |
elif pro!=4 : | |
if pro==5: | |
mass_of_solute, molar_mass, mass_of_solution= molarity(mass_of_solute, molar_mass, mass_of_solution) | |
elif pro==6: | |
mass_of_solute,molar_mass,mass_of_solution= molality(mass_of_solute,molar_mass,mass_of_solution) | |
elif pro==7: | |
mass_of_solute,mass_of_solution=mole_fraction(mass_of_solute,mass_of_solution,molar_mass,molar_mass_solvent) | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment