Variables and Arithmetic Operators#
Variables for saving values#
To save a value, we assign them to a variable for later use.
The syntax for assigning variables is:
variable_name = variable_value
.
Use print(variable_name)
to print the specified variable.
Tips:
Choose informative names for variables.
Use comment lines (lines with
#
) to express the units of the variable or to describe the meaning of the variable.
Arithmetic operators for calculations#
Common arithmetic operators are:
+
for addition-
for subtraction*
for multiplication\
for division**
for power operations.
Examples#
Please pay attention to the use of comments (with #
) to express the units of variables or to describe the meaning of commands.
Example
How many grams of solid NaOH (40.0 g/mol) are required to prepare 500 ml of a 40 mM solution?
Use \(Mass\) \((g)\) = \(Molar\) \(Concentration\) \((mol/l)\) x \(Volume\) \((l)\) \(Molecular\) \(Weight\) \((g/mol)\)
V = 0.5 #l
M = 0.04 #mol/l
MW = 40.0 #g/mol
m = (V * M) * MW #(l * mol/l) * g/mol = g
print(m) #print the value that we calculated
0.8
Example
How many ml of a 1 M Tris solution do you need to make 5 ml of a 0.25 M solution?
Use \(C_{initial}\) \(V_{initial}\) = \(C_{final}\) \(V_{final}\)
with
\(V_{initial}\) = volume of stock solution needed to make the new solution
\(C_{initial}\) = concentration of the stock solution
\(V_{final}\) = final volume of the new solution
\(C_{final}\) = final concentration of the new solution
Vfinal = 5 #ml
Cfinal = 0.25 #mol/l
Cinitial = 1 #mol/l
Vinitial = (Cfinal * Vfinal) / Cinitial #(mol/l * ml) / mol/l = ml
print(Vinitial) #print the value that we calculated
1.25
Exercises#
Exercise
You need 250 ml 50 mM NaCl. You have a 2 M NaCl stock solution. How many ml of 2 M NaCl do you need?
Solution
Here’s one possible solution.
Vfinal = 0.25 #l
Cfinal = 0.05 #mol/l
Cinitial = 2 #mol/l
Vinitial = (Cfinal * Vfinal) / Cinitial #(l * mol/l) / mol/l = l
Vinitialml = Vinitial*1000 #l/1000 = ml
print(Vinitialml) #print the value that we calculated
Exercise
You have 1 g of ATP (551.1 g/mol). You need a 100 mM solution. How much solution (in ml) can you make?
Solution
Here’s one possible solution.
m = 1 #g
M = 0.1 #mol/l
MW = 551.1 #g/mol
V = (m / MW) / M #(g * g/mol) * mol/l = l
Vml = V*1000 #l/1000 = ml
print(Vml) #print the value that we calculated