-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perform_Titration.py
203 lines (175 loc) · 8.54 KB
/
Perform_Titration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import sys
import math
def MainMenu():
print(' ')
print("Main Menu")
print("1 Solve for pH when titrating a base with an acid")
print("2 Solve for pH when titrating an acid with a base")
print("Q To Quit")
print(' ')
user_input= input("Enter a choice> ")
while user_input not in ['1','2','Q','q']:
user_input= input("Enter a choice> ")
if user_input == '1':
return TitrateBaseWithAcid()
elif user_input == '2':
return TitrateAcidWithBase()
elif user_input in ['Q','q']:
sys.exit(0)
def TitrateBaseWithAcid():
print(' ')
print("Menu: Titrate Base With Acid")
print(' ')
print("T Calculate number of liters of titrant needed for equivalence point")
print("1 Solve for pH before equivalence point")
print("E Solve for pH at equivalence point")
print("2 Solve for pH after equivalence point")
print("D Done")
print(' ')
user_input = input("Enter a choice> ")
while user_input not in ['1','2','E','e','D','d','T','t']:
user_input = input("Enter a choice> ")
if user_input in ['T','t']:
#Ct = OnlyAcceptsFloating(Ct,"Enter molarity of titrant> ")
#Ct = float(Ct)
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of intial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vt = (Co*Vo)/Ct
print("Equivalence point occurs when %f liters of titrant are added." % (Vt))
return TitrateBaseWithAcid()
elif user_input in ['D','d']:
return MainMenu()
elif user_input == '1':
K = float(input("Enter Kb constant> "))
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of intial solution> "))
Vo = float(input("Enter volume of intial solution before addition of titrant (liters)> "))
Vt = 0.1
while Vt != 0:
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
while Vt >= (Co*Vo)/Ct:
print("Volume of titrant is too large. You are before or at the equivalence point.")
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
if Vt != 0:
pH_one = 14 + math.log10(((-K*Vo-K*Vt-Ct*Vt)+ (((K*Vo+K*Vt+Ct*Vt)**2)-(4*(Vt+Vo)*(K*Ct*Vt-K*Co*Vo)))**0.5)/(2*(Vt+Vo)))
print("pH: %f" % pH_one)
return TitrateBaseWithAcid()
elif user_input in ['E','e']:
print("Is this reaction between a strong acid and strong base? Y/N")
user_input = input("Enter Y or N ")
while user_input not in ['y','Y','n','N']:
user_input = input("Enter Y or N ")
if user_input in ['Y','y']:
print("The pH at the equivalence point is 7.")
return TitrateBaseWithAcid()
else:
K = float(input("Enter Kb constant> "))
K = (1*(10**-14))/K
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of initial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vt = (Co*Vo)/Ct
Co = ((Co*Vo)/(Vt+Vo))
#pH_one = -math.log10((K + ((K**2 + 4*(K*Co)))**0.5)/-2)
pH = -math.log10((K - ((K**2 + 4*(K*Co)))**0.5)/-2)
print("The pH at the equivalence point is %f" % (pH))
return TitrateBaseWithAcid()
elif user_input == '2':
K = float(input("Enter Kb constant> "))
K = (1*(10**-14))/K
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of initial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vte = (Co*Vo)/Ct
Cotwo = ((Co*Vo)/(Vte+Vo))
Vt = 0.1
while Vt != 0:
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
while Vt <= (Co*Vo)/Ct:
print("Volume of titrant is too small. You are before or at the equivalence point.")
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
if Vt!= 0:
CoTwo = (K - ((K**2 + 4*(K*Cotwo)))**0.5)/-2
pH = -math.log10(((Ct*Vt-Co*Vo)/(Vt+Vo)) + CoTwo)
print("pH: %f" % pH)
return TitrateBaseWithAcid()
def TitrateAcidWithBase():
print(' ')
print("Menu: Titrate Acid With Base")
print(' ')
print("T Calculate number of liters of titrant needed for equivalence point")
print("1 Solve for pH before equivalence point")
print("E Solve for pH at equivalence point")
print("2 Solve for pH after equivalence point")
print("D Done")
print(' ')
user_input = input("Enter a choice> ")
while user_input not in ['1','2','E','e','D','d','t','T']:
user_input = input("Enter a choice> ")
if user_input in ['T','t']:
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of intial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vt = (Co*Vo)/Ct
print("Equivalence point occurs when %f liters of titrant are added." % (Vt))
return TitrateAcidWithBase()
elif user_input in ['D','d']:
return MainMenu()
elif user_input == '1':
K = float(input("Enter Ka constant> "))
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of intial solution> "))
Vo = float(input("Enter volume of intial solution before addition of titrant (liters)> "))
Vt = 0.1
while Vt != 0:
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
while Vt >= (Co*Vo)/Ct:
print("Volume of titrant is too large. You are before or at the equivalence point.")
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
if Vt != 0:
pH_one = -math.log10(((-K*Vo-K*Vt-Ct*Vt)+ (((K*Vo+K*Vt+Ct*Vt)**2)-(4*(Vt+Vo)*(K*Ct*Vt-K*Co*Vo)))**0.5)/(2*(Vt+Vo)))
print("pH: %f" % pH_one)
else:
return TitrateAcidWithBase()
elif user_input in ['E','e']:
print("Is this reaction between a strong acid and strong base? Y/N")
user_input = input("Enter Y or N ")
while user_input not in ['y','Y','n','N']:
user_input = input("Enter Y or N ")
if user_input in ['Y','y']:
print("The pH at the equivalence point is 7.")
return TitrateAcidWithBase()
else:
K = float(input("Enter Ka constant> "))
K = (1*(10**-14))/K
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of initial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vt = (Co*Vo)/Ct
Co = ((Co*Vo)/(Vt+Vo))
#pH_one = -math.log10((K + ((K**2 + 4*(K*Co)))**0.5)/-2)
pH = 14 + math.log10((K - ((K**2 + 4*(K*Co)))**0.5)/-2)
print("The pH at the equivalence point is %f" % (pH))
return TitrateAcidWithBase()
elif user_input == '2':
K = float(input("Enter Ka constant> "))
K = (1*(10**-14))/K
Ct = float(input("Enter molarity of titrant> "))
Co = float(input("Enter molarity of initial solution> "))
Vo = float(input("Enter volume (liters) of intial solution> "))
Vte = (Co*Vo)/Ct
Cotwo = ((Co*Vo)/(Vte+Vo))
Vt = 0.1
while Vt != 0:
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
while Vt <= (Co*Vo)/Ct:
print("Volume of titrant is too small. You are before or at the equivalence point.")
Vt = float(input("Enter volume of titrant added (liters). Enter 0 to stop> "))
if Vt != 0:
CTwo = (K - ((K**2 + 4*(K*Cotwo)))**0.5)/-2
pH = 14+ math.log10(((Ct*Vt-Co*Vo)/(Vt+Vo)) + CTwo)
print("pH: %f" % pH)
return TitrateAcidWithBase()
if __name__ == "__main__":
MainMenu()