Solutions
Video
Code
1. You have been provided with the following electronegativity data for selected groups of the periodic table.
electronegativities = {
'group 1': (0.98, 0.93, 0.82, 0.82, 0.79, 0.79),
'group 2': (1.57, 1.31, 1.00, 0.95, 0.89, 0.90),
'group 13': (2.04, 1.61, 1.81, 1.78, 1.62),
'group 14': (2.55, 1.90, 2.01, 1.96, 1.87),
'group 15': (3.04, 2.19, 2.18, 2.05, 2.02),
'group 16': (3.44, 2.58, 2.55, 2.10, 2.00),
'group 17': (3.98, 3.16, 2.96, 2.66, 2.20)
}To find the mean electronegativities for groups 1 and 2 we can sum the group and divide by the number of elements
g1_mean_chi = sum(electronegativities['group 1']) / len(electronegativities['group 1'])
g2_mean_chi = sum(electronegativities['group 2']) / len(electronegativities['group 1'])
difference = g1_mean_chi - g2_mean_chi2. Consider the following blocks of code. Each one of them will cause an error when run.
Block 1
The object functional_groups is a tuple and so is immutable - we cannot add modify its elements, or add/remove any.
To make this code work we can change functional_groups to a list which is mutable
functional_groups = ['Aldehyde', 'Ketone', 'Ester', 'Ether']
functional_groups.append('Amine')
print(f'Here is a selection of functional groups: {functional_groups}')Block 2
Python gives the following error
Traceback (most recent call last):
Cell In[7], line 16
lattice_energy = (k * v * z_plus * z_minus) / (radius_Na + radius_Cl)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'int' and 'str'which is telling us that we annot divide an int by a str. We don’t want a string in our equation, so lets look at each variable. We can either look at the code, or use type to see that k, v, z_plus and z_minus all int, so clearly these aren’t the issue. However, radius_Na and radius_Cl are str - why?
The line
radius_Na = group_1_radii[2]defines radius_Na as the third element of the group_1_radii tuple - which is made up of strings! Simply changing the tuples to contain int or float will make this code work.
# Kapustinskii equation constant in kJ pm mol-1
k = 107900
# Lithium, Sodium, Potassium, Rubidium radii in pm
group_1_radii = (90, 116, 152, 166)
# Fluorine, Chlorine, Bromine, Iodine radii in pm
group_7_radii = (119, 167, 182, 206)
v = 2
z_plus = 1
z_minus = 1
radius_Na = group_1_radii[2]
radius_Cl = group_7_radii[2]
lattice_energy = (k * v * z_plus * z_minus) / (radius_Na + radius_Cl)
print(f'The lattice energy of NaCl is: {lattice_energy:.2f} kJ mol-1')The lattice energy of NaCl is: 646.11 kJ mol-1
But if you look up the lattice energy of NaCl you’ll find its actualy more like \(787 \mathrm{kJ\, mol^{-1}}\), so why is our value so far off?
Take another look at the definition of radius_Na, we use the third element of group_1_radii as specified by the index 2. But the comment above the definition of group_1_radii tells us that sodium is the second element of the tuple - i.e. it has the index 1. Fixing this gives
# Kapustinskii equation constant in kJ pm mol-1
k = 107900
# Lithium, Sodium, Potassium, Rubidium radii in pm
group_1_radii = (90, 116, 152, 166)
# Fluorine, Chlorine, Bromine, Iodine radii in pm
group_7_radii = (119, 167, 182, 206)
v = 2
z_plus = 1
z_minus = 1
radius_Na = group_1_radii[1]
radius_Cl = group_7_radii[1]
lattice_energy = (k * v * z_plus * z_minus) / (radius_Na + radius_Cl)
print(f'The lattice energy of NaCl is: {lattice_energy:.2f} kJ mol-1')The lattice energy of NaCl is: 762.54 kJ mol-1
which is much closer to the literature value!