Solutions#
1. Calculate the energy of a photon (in Joules) with frequency
where
import scipy
v = 2.18e10 # GHz
v *= 1e9 # Convert to Hz
E = scipy.constants.h * v
print(f'The energy of the photon is {E} J.')
The energy of the photon is 1.4444832927e-14 J.
2. Calculate the wavelengths (in nanometres) corresponding to the first line in the Lyman, Balmer and Paschen series. You will need the following relation:
where
n_1 = 1
n_2 = 2
wavelength = 1 / (scipy.constants.Rydberg * (1 / n_1 ** 2 - 1 / n_2 ** 2))
wavelength *= 10 ** 9 # Convert to nm
print(f'The first line of the Lyman series occurs at {wavelength} nm.')
n_1 = 2
n_2 = 3
wavelength = 1 / (scipy.constants.Rydberg * (1 / n_1 ** 2 - 1 / n_2 ** 2))
wavelength *= 10 ** 9 # Convert to nm
print(f'The first line of the Balmer series occurs at {wavelength} nm.')
n_1 = 3
n_2 = 4
wavelength = 1 / (scipy.constants.Rydberg * (1 / n_1 ** 2 - 1 / n_2 ** 2))
wavelength *= 10 ** 9 # Convert to nm
print(f'The first line of the Paschen series occurs at {wavelength} nm.')
The first line of the Lyman series occurs at 121.5022734110182 nm.
The first line of the Balmer series occurs at 656.1122764194981 nm.
The first line of the Paschen series occurs at 1874.6065040557094 nm.
3. Consider the following blocks of code. Each one of them will cause an error when run. Taking each block one-by-one:
Predict which line of code will cause the error and why this line is problematic.
Run the block of code in a Jupyter notebook and see whether or not you were correct.
Modify the code to solve the problem and thus remove the error.
Block 1:
a = 32
b = '64'
print(a + b)
a = 32
b = 64
print(a + b)
96
Block 2:
string_variable = 'Python is pretty cool! '
repeat = 4.0
print(string_variable * repeat)
string_variable = 'Python is pretty cool! '
repeat = 4
print(string_variable * repeat)
Python is pretty cool! Python is pretty cool! Python is pretty cool! Python is pretty cool!
Block 3: This code uses the following expression for the root mean square speed of a molecule:
where
Note
This block also contains a problem which, whilst it will not cause an error, will lead to the wrong result being calculated. See if you can spot and fix this problem in addition to removing the error.
import math
import scipy
# You do not have to include the imports above if you have already imported math and scipy in your notebook.
temperature = 500
molar_mass = 31.998 / 1000 # molar mass of oxygen in kgmol-1
# Calculate the root mean square speed of an oxygen molecule at 500 K
rms_speed = math.sqrt{3 * scipy.constants.R * temperature / molar_mass}
print(f'The root mean square speed of an O2 molecule at 500 K is {rms_speed} ms-1.')
import math
import scipy
# You do not have to include the imports above if you have already imported math and scipy in your notebook.
temperature = 500
molar_mass = 31.998 / 1000
# Calculate the root mean square speed of an oxygen molecule at 500 K
rms_speed = math.sqrt((3 * scipy.constants.R * temperature) / molar_mass)
print(f'The root mean square speed of an O2 molecule at 500 K is {rms_speed} ms-1.')
The root mean square speed of an O2 molecule at 500 K is 624.3114571475151 ms-1.
Block 4: This code is trying to solve the following equation,
using the quadratic formula:
print = 'This code calculates the solutions to 5x^2 + 12x + 7'
a = 5
b = 12
c = 7
solution_1 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
solution_2 = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
print(f'The solutions are {solution_1} and {solution_2}')
print('This code calculates the solutions to 5x^2 + 12x + 7')
a = 5
b = 12
c = 7
solution_1 = (-b + math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
solution_2 = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
print(f'The solutions are {solution_1} and {solution_2}')
This code calculates the solutions to 5x^2 + 12x + 7
The solutions are -1.0 and -1.4