#Imported Modules Tclass1 Acid Tclass2 Base Tmod T Math Random
#Imported Modules Tclass1 Acid Tclass2 Base Tmod T Math Random
Ashley Hong
cs50AP spring project
3 May 2019
'''
#imported modules
from tclass1 import Acid
from tclass2 import Base
import tmod as t
import math
import random
def main():
#introduction page for titration
print("WELCOME to the Virtual Acid/Base titration lab.")
print("With the use of this program, You can create a simulation of the
lab before attempting the actual lab.")
#transition
print("The next step is choosing the actual acid and base from the list
provided.")
#list of acid and base
strongacid = ['HCL', 'HBR', 'HI']
strongbase = ['KOH', 'LIOH', 'NAOH']
print("\n")
#gives user random option
choice = input("Would you like a random option (y/n):")
if(choice == 'y'):
#choice procedure
t.choice()
else:
print("\n")
#gives acid list
print(strongacid)
#name of acid
aname = input("Enter the chosen Acid:")
if(aname.upper() in strongacid):
#user guide
print(" TIP: The usual concentration for a strong acid is
(.01 -.9)")
acon = float(input("Enter the concentration for the Acid:"))
else:
print("Please Enter the correct acid from the list.")
#if incorrect acid listed, returns 1
print("Try again")
return 1
acid = Acid(aname, acon)
#class for acid to print name adn concentration
acid.printAcid()
print("\n")
#prints base list
print(strongbase)
#name of base
bname = input("Enter the chosen Base:")
if(bname.upper() in strongbase):
print(" TIP: The usual concentration for a strong base is
(.01 -.9)")
bcon = float(input("Enter the concentration for the Base:"))
else:
print("Please enter the correct base fromt the list")
#returns 1 if name not in list
print("Try again")
return 1
base = Base(bname, bcon)
#class for base name and concentration
base.printBase()
for x in range(2):
print("\n")
print("Now with the given input, let's create the chemical reaction for
this titration.")
#creating chemical reaction equasion
t.equationstrong()
#conclusion
print("\n")
print("We have now successfully completed the Titration Simulator.")
print("Now apply this knowledge to be able to apply it to a real
experiment.")
print("Thank you for your time")
#main format
if( __name__ ) == "__main__":
main()
'''
Ashley Hong
cs50AP spring mod
3 May 2019
'''
#procedures
def choice():
#list of strong acid and base
strongacid = ['HCL', 'HBR', 'HI']
strongbase = ['KOH', 'LIOH', 'NAOH']
#chooses a raondom int with python function
x = random.randint(0,2)
#chooses random acid with chosennuber
acid = strongacid[x]
#user guide
print(" TIP: The usual concentration for a strong acid is (.01 -.9)")
#finds concentration of acid with user input
acon = float(input("Enter a concentration for the acid:"))
#chooses another random integer
y = random.randint(0,2)
print(" TIP: The usual concentration for a strong base is (.01 -.9)")
#concentration of base with user input
bcon = float(input("Enter a concentration for the base:"))
#chooses strong base from list
base = strongbase[y]
#prints chosen values
print("For this reaction, {} was chosen with {} M
concentration.".format(acid, acon))
print("For this reaction, {} was chosen with {} M
concentration.".format(base, bcon))
def equationstrong():
#prints the chemical reactions
print("For the titration, we will create the chemical reaction.")
print("Please re-enter the chosen acid and base.")
print("\n")
print("The chemcial reaction is:")
#uses format (python function) to print compounds and their formula
print("{} + {} = {}{} + H2O ".format(acidname.upper() ,basename.upper(),
basename3.upper(), acidname3.upper()))
print("\n")
def indicator(x):
#raspberry pi component
red = 7
blue = 13
#for first indicator
if(x == 1):
step = input("Is it BEFORE/AT/AFTER the equivalence point:")
# it is first step
if(step.lower() == "before"):
#GPIO settings
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(red, GPIO.OUT)
#turn LED on
print("led on")
GPIO.output(red, GPIO.OUT)
#hod for five seconds
time.sleep(5)
print("led off")
#turn LEF off
GPIO.output(red, GPIO.LOW)
time.sleep(.5)
#at equivalence point
elif(step.lower() == "at"):
#GPIO settings
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(blue, GPIO.OUT)
#LED on
print("led on")
GPIO.output(blue, GPIO.OUT)
time.sleep(5)
print("led off")
#LED off
GPIO.output(blue, GPIO.LOW)
time.sleep(.5)
#passing equivalence point
elif(step.lower() == "after"):
#GPIO settings
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(red, GPIO.OUT)
print("led on")
GPIO.output(red, GPIO.OUT)
time.sleep(5)
print("led off")
GPIO.output(red, GPIO.LOW)
time.sleep(.5)
#functions
def equil(y,z):
#equivalence point volume
#introduction
print("For the first step, You must choose the volume of the analyte
being used.")
print("Now that we have chosen the analyte volume we will use the
titration formula to find the Equivalence point")
#with the given analyte
analyte = input("What is the analyte (acid or base):")
print("\n")
#if the analyte is an acid
if(analyte.lower() == "acid"):
#simplify code using lambda function
#returns found equilibrium volume
return lambda x: ((x/1000) * y / z )
#if the analyte is a base
elif(analyte.lower() == "base"):
#simplify with lambda function
3#returns equilibiurm volume
return lambda x: ((x/1000) * z / y)
#a = acid concen
#b = acid volume
#c = base concen
#d = titrant volume
#e = analyte
def ph(a,b,c,d,e):
#calculating the pH of solutions
step = int(input("What step of the titration is this (1/2/3):"))
#step one
if(step == 1):
#uses round (python function) to return rounded result
# log to find pH
if(e == "acid"):
print("The pH is:")
return round((-math.log(a,10)),3)
if(e == "base"):
print("The pH is:")
return round((14 -(-math.log(a,10))),3)
#step 2
elif(step == 2):
#moles of analyte and titrant
anmoles = (b/1000) * a
timoles = (d/1000) * c
molarity = (anmoles - timoles) + (1.0*10**-7)
#uses round (python function) to return rounded result
#log to find pH
if(e == "acid"):
print("The pH is:")
return round((- math.log(molarity,10)),3)
if(e == "base"):
print("The pH is:")
return round((- math.log(molarity,10)),3)
#step 3
elif(step == 3):
#moles of analyte
anmoles = (b/1000) * a
timoles = (d/1000) * c
#moles of base
oh = timoles - anmoles
#molarity
molarity2 = oh/(b + d)
poh = (- math.log(molarity2,10))
#uses round (python function) to return rounded result
#log to find pH
if(e == "acid"):
print("The pH is:")
return round((14 - poh),3)
if(e == "base"):
print("The pH is:")
return round((poh),3)
'''
Ashley Hong
cs50AP spring class1
3 May 2019
'''
#ACID class
#create class for acid
class Acid():
#first field for acid name
acidname = ""
#next field for acid concentration
acidconcentration = 0
#two getters
def getAcidName(self):
#return the self.acidname
return self.acidname
def getAcidConcentration(self):
#return the self.acidconcentration
return self.acidconcentration
#two setters
def setAcidName(self, acid):
self.acidname = acid
def printAcid(self):
#displays fields to user, statement for user to show the chosen acid
and concentration
#uses format (python function)
print("For this reaction, {} was chosen with {} M
concentration.".format(self.getAcidName() , self.getAcidConcentration()))
'''
Ashley Hong
cs50AP spring class2
3 May 2019
'''
#BASE calss
#creating class for base
class Base():
#first field
#base name field
basename = ""
#next field
#field for base concentration
baseconcentration = 0
#two getters
def getBaseName(self):
return self.basename
def getBaseConcentration(self):
return self.baseconcentration
#two setters
def setBaseName(self, base):
self.basename = base
def printBase(self):
#user displayed statement showing two fields and the chosen name and
concentration
#uses format (python function)
print("For this reaction, {} was chosen with {} M
concentration.".format(self.getBaseName() , self.getBaseConcentration()))
~/workspace/spring/ $ python titration.py
WELCOME to the Virtual Acid/Base titration lab.
With the use of this program, You can create a simulation of the lab before
attempting the actual lab.
First let's choose the whether the acid or base is the titrant/analyte.
Would you like a definition of each (y/n):n
Now with the given input, let's create the chemical reaction for this
titration.
For the titration, we will create the chemical reaction.
Please re-enter the chosen acid and base.
Re-enter the acid you chose:hbr
Re-enter the base you chose:naoh
There are 3 checkpoints where you must find the PH of the solution.
1. Before the titration
2. At the equivalence point
3. After the equivalence point
Now that we have prepared the theoretical volume, let's begin actual
titration
At the beginning of the titration the Ph of the solution is:
Is it BEFORE/AT/AFTER the equivalence point:before
#look at video
led on
led off
What step of the titration is this (1/2/3):1
The pH is:
12.301
Until 200.0 mL, add ____ mL and watch the pH change/indicator change
Add titrant(mL):100
100.0
Add titrant(mL):100
200.0
Is it BEFORE/AT/AFTER the equivalence point:at
#look at video
led on
led off
What step of the titration is this (1/2/3):2
The pH is:
7.0
We will check the pH past the equivalence point.
Choose a volume that is greater than 200.0 and less than 400.0
Add titrant past equivalence point(mL):300
Is it BEFORE/AT/AFTER the equivalence point:after
#look at video
led on
led off
What step of the titration is this (1/2/3):3
The pH is:
5.602
Now with the given input, let's create the chemical reaction for this
titration.
For the titration, we will create the chemical reaction.
Please re-enter the chosen acid and base.
Re-enter the acid you chose:HCL
Re-enter the base you chose:LIOH
There are 3 checkpoints where you must find the PH of the solution.
1. Before the titration
2. At the equivalence point
3. After the equivalence point
Now that we have prepared the theoretical volume, let's begin actual
titration
At the beginning of the titration the Ph of the solution is:
Is it BEFORE/AT/AFTER the equivalence point:before
#look at video
led on
led off
What step of the titration is this (1/2/3):1
The pH is:
1.301
Until 85.71 mL, add ____ mL and watch the pH change/indicator change
Add titrant(mL):10
10.0
Add titrant(mL):20
30.0
Add titrant(mL):30
60.0
Add titrant(mL):20
80.0
Add titrant(mL):5.71
85.71
Is it BEFORE/AT/AFTER the equivalence point:at
#look at video
led on
led off
What step of the titration is this (1/2/3):2
The pH is:
6.398
We will check the pH past the equivalence point.
Choose a volume that is greater than 85.71 and less than 171.43
Add titrant past equivalence point(mL):115
Is it BEFORE/AT/AFTER the equivalence point:after
#look at video
led on
led off
What step of the titration is this (1/2/3):3
The pH is:
8.941