The idea for this exercise is to copy and paste the tests and the function definitions into your own Notebook.
Once the function that your write satifies the test, only 'Test X for Problem Y Passed!'
will be printed when the cell is run.
Unless otherwise stated, all values are in SI units.
import numpy as np
The first function should produce the energy of a photon given a particular wavenumber. Note that the speed of light and Planck's constant are imported from the scipy.constants
library as c
and h
respectively.
from scipy.constants import c, h
def energy(wavenumber):
return
np.testing.assert_almost_equal(energy(5.03411665e24), 1)
print('Test 1 for Problem 1 Passed!')
np.testing.assert_almost_equal(energy(755117497.6671815), 1.5e-16)
print('Test 2 for Problem 1 Passed!')
np.testing.assert_almost_equal(energy(5.663381232503861e+28), 11250.000186762287)
print('Test 3 for Problem 1 Passed!')
The second function should be able to determine the volume of a system (assuming the gas is ideal) given the number of moles of gas R
.
Remember,
from scipy.constants import R
def ideal_gas_law(number_of_moles, temperature, pressure):
return
np.testing.assert_almost_equal(ideal_gas_law(100, 100, 101325), 0.82057367)
print('Test 1 for Problem 2 Passed!')
np.testing.assert_almost_equal(ideal_gas_law(1, 500, 10132500), 4.10286691e-04)
print('Test 2 for Problem 2 Passed!')
np.testing.assert_raises(ValueError, ideal_gas_law, 1, -1, 10)
print('Test 3 for Problem 2 Passed!')
This function should return the allowed values of the angular momentum quantum number
Remember,
def allowed_angular_momentum_quantum_numbers(principal_quantum_number):
return
np.testing.assert_equal(allowed_angular_momentum_quantum_numbers(3), [0, 1, 2])
print('Test 1 for Problem 3 Passed!')
np.testing.assert_equal(allowed_angular_momentum_quantum_numbers(6), [0, 1, 2, 3, 4, 5])
print('Test 2 for Problem 3 Passed!')
np.testing.assert_raises(ValueError, allowed_angular_momentum_quantum_numbers, 0)
print('Test 3 for Problem 3 Passed!')
np.testing.assert_raises(TypeError, allowed_angular_momentum_quantum_numbers, 1.5)
print('Test 4 for Problem 3 Passed!')
This function should return the rate constants
Remember,
def arrhenius_equation(pre_exponential_factor, activation_energy, temperature):
return
np.testing.assert_almost_equal(arrhenius_equation(23e10, 24.131, 300), 227785637794.47137)
print('Test 1 for Problem 4 Passed!')
np.testing.assert_almost_equal(arrhenius_equation(29, 10, np.array([6, 26, 226])),
[23.7324167, 27.6890556, 28.8460781])
print('Test 2 for Problem 4 Passed!')
Write a function to calculate the energy of a Morse potential (this potential is a good model of a chemical bond) at a given set of distances. The functional form of a Morse potential is,
where
def morse(dissociation_energy, r, r_e):
return
np.testing.assert_almost_equal(morse(4.52, np.linspace(0.5, 1, 10), 0.74),
[0.332564 , 0.1854401, 0.0855355, 0.0261688,
0.0014542, 0.0062124, 0.0358916, 0.0864975,
0.1545298, 0.2369265])
print('Test 1 for Problem 5 Passed!')
np.testing.assert_almost_equal(morse(0.59, 5, 1.5), 0.5549050979213414)
print('Test 2 for Problem 5 Passed!')