# Dictionary for elements and masses (EXPAND)
masses = {
"H": 1.008,
"He": 4.0026,
"Li": 6.94,
"Be": 9.0122,
"B": 10.81,
"C": 12.011,
"N": 14.007,
"O": 15.999,
"F": 18.998,
"Ne": 20.180,
"Na": 22.990,
"Mg": 24.305,
"Al": 26.982,
"Si": 28.085,
"P": 30.974,
"S": 32.06,
"Cl": 35.45,
"Ar": 39.948
}
# constant definitions
A = 6.022*10**23
h = 6.626*10**-34
# define functions for all actions
def moletogram():
element = input("Enter the elemental symbol of the element in question")
moles = int(input("Enter the number of moles of " + element))
molarmass = masses[element]
grams = moles * molarmass
print("The number of grams is " + str(grams))
def gramtomole():
element = input("Enter the elemental symbol of the element in question")
grams = int(input("Enter the number of grams of " + element))
molarmass = masses[element]
moles = grams / molarmass
print("The number of moles is " + str(moles))
def moletomolecule():
moles = int(input("Enter the number of moles in question"))
molecules = moles * A
print("The number of molecules is " + str(molecules))
def gramtomolecule():
element = input("Enter the elemental symbol of the element in question")
grams = int(input("Enter the number of grams of " + element))
molarmass = masses[element]
moles = grams / molarmass
molecules = moles * A
print("The number of molecules is " + str(molecules))
def PVnRT():
solvefor = input("What variable would you like to solve for?")
R = 0.08206
if solvefor.lower() == "p" or solvefor.lower() == "pressure":
# P = nRT/V
volume = int(input("Enter the volume of the gas in liters"))
moles = int(input("Enter the moles of the gas"))
temp = int(input("Enter the temperature of the gas in Kelvin"))
pressure = moles * R * temp / volume
print("The pressure is " + str(pressure) + " atm")
elif solvefor.lower() == "v" or solvefor.lower() == "volume":
# V = nRT/P
pressure = int(input("Enter the pressure of the gas in atm"))
moles = int(input("Enter the moles of the gas"))
temp = int(input("Enter the temperature of the gas in Kelvin"))
volume = moles * R * temp / pressure
print("The volume is " + str(volume) + " liters")
elif solvefor.lower() == "n" or solvefor.lower() == "moles":
# n = PV/RT
pressure = int(input("Enter the pressure of the gas in atm"))
volume = int(input("Enter the volume of the gas in liters"))
temp = int(input("Enter the temperature of the gas in Kelvin"))
moles = pressure * volume / R / temp
print("The number of moles is " + str(moles) + " moles")
elif solvefor.lower() == "t" or solvefor.lower() == "temperature" or solvefor.lower() == "temp":
# T = PV/nR
pressure = int(input("Enter the pressure of the gas in atm"))
volume = int(input("Enter the volume of the gas in liters"))
moles = int(input("Enter the moles of the gas"))
temp = pressure * volume / moles / R
print("The temperature is " + str(temp) + " Kelvin")
else:
print("You did not enter a valid variable. Please try again!")
def Ehv():
solvefor = input("What variable would you like to solve for?")
if solvefor.lower() == "e" or solvefor.lower() == "energy":
# E = hv
frequency = int(input("Enter the frequency in Hz"))
E = h * frequency
Ekj = E / 1000
print("The energy is " + str(E) + " joules, or " + str(Ekj) + " kilojoules")
elif solvefor.lower() == "v" or solvefor.lower() == "frequency":
# = v = E / h
E = int(input("Enter the energy in joules"))
frequency = E / h
print("The frequency is " + str(frequency) + " Hz")
else:
print("You did not enter a valid variable. Please try again!")
# Welcome
print("Hello, welcome to this Chemistry aid and convenience tool.")
# List of actions possible
actions = [
"1. Convert moles to grams",
"2. Convert grams to moles",
"3. Convert moles to molecules",
"4. Convert grams to molecules.",
"5. PV=nRT",
"6. E = hv"
]
# Get user input of which action to do
while True:
print("Options:")
for i in range(len(actions)):
print(actions[i])
action = input("Please input the number of the corresponding action you would like to do or 'q' to exit.")
if action == "1":
moletogram()
elif action == "2":
gramtomole()
elif action == "3":
moletomolecule()
elif action == "4":
gramtomolecule()
elif action == "5":
PVnRT()
elif action == "6":
Ehv()
elif action == "q":
break
else:
print("You did not enter a valid option. Please try again!")
# Implement iteration maybe by checking if what they input is a valid input
# OR implement with maybe having a rating thing at the end with multiple numbers and use iteration to check if all numbers