W04 Prove Milestone: Chemistry
Purpose
Prove that you can write a Python program that creates and uses a compound list.
Problem Statement
In chemistry, a mole is a very large, fixed quantity, specifically 602,214,076,000,000,000,000,000 (usually written as 6.02214076 × 1023). The molar mass of a substance is the mass in grams of one mole of the substance (grams / mole). A molar mass calculator is a program that computes the molar mass of a substance and the number of moles of a sample of that substance. To use a molar mass calculator, a chemist enters two inputs:
-
The formula for a molecule, such as H2O (water) or C6H12O6 (glucose)
-
The mass in grams of a sample of the substance, such as 3.71
The calculator computes the molar mass of the molecule and the number of moles in the sample and then prints both of those numbers.
Table of Elements
There are 94 chemical elements known to occur naturally on earth. The symbol, name, and atomic mass of all 94 elements are shown in the following table.
Symbol | Name | Atomic Mass |
---|---|---|
"Ac", | "Actinium", | 227 |
"Ag", | "Silver", | 107.8682 |
"Al", | "Aluminum", | 26.9815386 |
"Ar", | "Argon", | 39.948 |
"As", | "Arsenic", | 74.9216 |
"At", | "Astatine", | 210 |
"Au", | "Gold", | 196.966569 |
"B", | "Boron", | 10.811 |
"Ba", | "Barium", | 137.327 |
"Be", | "Beryllium", | 9.012182 |
"Bi", | "Bismuth", | 208.9804 |
"Br", | "Bromine", | 79.904 |
"C", | "Carbon", | 12.0107 |
"Ca", | "Calcium", | 40.078 |
"Cd", | "Cadmium", | 112.411 |
"Ce", | "Cerium", | 140.116 |
"Cl", | "Chlorine", | 35.453 |
"Co", | "Cobalt", | 58.933195 |
"Cr", | "Chromium", | 51.9961 |
"Cs", | "Cesium", | 132.9054519 |
"Cu", | "Copper", | 63.546 |
"Dy", | "Dysprosium", | 162.5 |
"Er", | "Erbium", | 167.259 |
"Eu", | "Europium", | 151.964 |
"F", | "Fluorine", | 18.9984032 |
"Fe", | "Iron", | 55.845 |
"Fr", | "Francium", | 223 |
"Ga", | "Gallium", | 69.723 |
"Gd", | "Gadolinium", | 157.25 |
"Ge", | "Germanium", | 72.64 |
"H", | "Hydrogen", | 1.00794 |
"He", | "Helium", | 4.002602 |
"Hf", | "Hafnium", | 178.49 |
"Hg", | "Mercury", | 200.59 |
"Ho", | "Holmium", | 164.93032 |
"I", | "Iodine", | 126.90447 |
"In", | "Indium", | 114.818 |
"Ir", | "Iridium", | 192.217 |
"K", | "Potassium", | 39.0983 |
"Kr", | "Krypton", | 83.798 |
"La", | "Lanthanum", | 138.90547 |
"Li", | "Lithium", | 6.941 |
"Lu", | "Lutetium", | 174.9668 |
"Mg", | "Magnesium", | 24.305 |
"Mn", | "Manganese", | 54.938045 |
"Mo", | "Molybdenum", | 95.96 |
"N", | "Nitrogen", | 14.0067 |
"Na", | "Sodium", | 22.98976928 |
"Nb", | "Niobium", | 92.90638 |
"Nd", | "Neodymium", | 144.242 |
"Ne", | "Neon", | 20.1797 |
"Ni", | "Nickel", | 58.6934 |
"Np", | "Neptunium", | 237 |
"O", | "Oxygen", | 15.9994 |
"Os", | "Osmium", | 190.23 |
"P", | "Phosphorus", | 30.973762 |
"Pa", | "Protactinium", | 231.03588 |
"Pb", | "Lead", | 207.2 |
"Pd", | "Palladium", | 106.42 |
"Pm", | "Promethium", | 145 |
"Po", | "Polonium", | 209 |
"Pr", | "Praseodymium", | 140.90765 |
"Pt", | "Platinum", | 195.084 |
"Pu", | "Plutonium", | 244 |
"Ra", | "Radium", | 226 |
"Rb", | "Rubidium", | 85.4678 |
"Re", | "Rhenium", | 186.207 |
"Rh", | "Rhodium", | 102.9055 |
"Rn", | "Radon", | 222 |
"Ru", | "Ruthenium", | 101.07 |
"S", | "Sulfur", | 32.065 |
"Sb", | "Antimony", | 121.76 |
"Sc", | "Scandium", | 44.955912 |
"Se", | "Selenium", | 78.96 |
"Si", | "Silicon", | 28.0855 |
"Sm", | "Samarium", | 150.36 |
"Sn", | "Tin", | 118.71 |
"Sr", | "Strontium", | 87.62 |
"Ta", | "Tantalum", | 180.94788 |
"Tb", | "Terbium", | 158.92535 |
"Tc", | "Technetium", | 98 |
"Te", | "Tellurium", | 127.6 |
"Th", | "Thorium", | 232.03806 |
"Ti", | "Titanium", | 47.867 |
"Tl", | "Thallium", | 204.3833 |
"Tm", | "Thulium", | 168.93421 |
"U", | "Uranium", | 238.02891 |
"V", | "Vanadium", | 50.9415 |
"W", | "Tungsten", | 183.84 |
"Xe", | "Xenon", | 131.293 |
"Y", | "Yttrium", | 88.90585 |
"Yb", | "Ytterbium", | 173.054 |
"Zn", | "Zinc", | 65.38 |
"Zr", | "Zirconium", | 91.224 |
Assignment
During this prove milestone and the next prove assignment, you
will write and test a molar mass calculator named
chemistry.py
. During this milestone, you will complete
part of the calculator by writing a function named
make_periodic_table
and the main
function.
The make_periodic_table
function must create and return
a compound list that contains data for all 94 naturally occuring
elements.
Helpful Documentation
-
If you are interested in the chemistry concepts involved in a molar mass calculator, you can watch this Khan Academy video titled Calculating molar mass and number of moles (6 minutes).
-
The preparation content for this week explains how to create and use a compound list.
-
The preparation content for week 03 explains how to use
pytest
,assert
, andapprox
to automatically verify that functions are correct. It also contains an example test function and links to additional documentation aboutpytest
.
Help from a Tutor
As a BYU-Pathway student you can get help from a tutor to help you complete your CSE 111 assignments. Each tutor is a current student employee. Meeting with a tutor is free. It will not cost you any money to meet with a tutor. To get help from a tutor, you simply make an appointment and then meet with the tutor. Tutors typically use Zoom to meet with students. To make an appointment, use the tutoring link on the course home page.
Steps
Do the following:
-
Using VS Code, create a new file and save it as
chemistry.py
-
In the
chemistry.py
file, write a function namedmake_periodic_table
that takes no parameters and creates and returns a compound list. The compound list must contain all the data in the table of elements shown in the Table of Elements section above. The data within the compound list must be organized like this:periodic_table_list = [ # [symbol, name, atomic_mass] ["Ac", "Actinium", 227], ["Ag", "Silver", 107.8682], ["Al", "Aluminum", 26.9815386], ⋮ ]
-
We strongly recommend that you do not type the data in the table of elements but instead that you copy and paste the data from this assignment into your program. If you don’t know how to use copy and paste to help you quickly write the
make_periodic_table
function, ask a fellow student, a tutor, a teaching assistant, or your teacher for help. -
After you copy and paste the periodic table data into your program, you must add square brackets ([ and ]) and commas (,) so that the data is organized in a compound list. If you’re using VS Code as your text editor, you can use multi-line editing to quickly add all the necessary square brackets and commas.
-
-
In the
chemistry.py
file, write themain
function that takes no parameters and returns nothing. Themain
function should do the following:-
Get a chemical formula for a molecule from the user.
-
Get the mass of a chemical sample in grams from the user.
-
Call the
make_periodic_table
function and store the returned list in a variable. -
Print the name and atomic mass for each chemical element on a separate line. Do not print the chemical element symbols.
-
-
At the bottom of your
chemistry.py
file, add a call to themain
function. Be certain to protect the call tomain
with anif
statement as taught in the preparation content for week 03.
Call Graph
The following call graph shows the user-defined functions and
function calls and returns as you should write them in your
chemistry.py
program. From this call graph we see the
following function calls:
-
The computer starts executing the
chemistr.py
program by calling themain
function. -
While executing the
main
function, the computer calls theinput
,float
make_periodic_table
, andprint
functions.
Testing Procedure
Verify that your program works correctly by following each step in this testing procedure:
-
Download the
test_chemistry_1.py
Python file and save it in the same folder where you saved yourchemistry.py
program. Run thetest_chemistry_1.py
file and ensure that thetest_make_periodic_table
function passes. If it doesn’t pass, there is a mistake in yourmake_periodic_table
function. Read the output frompytest
, fix the mistake, and run thetest_chemistry_1.py
file again until the test function passes.> python test_chemistry_1.py =================== test session starts ==================== platform win32--Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy rootdir: C:\Users\cse111\week04 collected 1 item test_chemistry_1.py::test_make_periodic_table PASSED [100%] ==================== 1 passed in 0.14s =====================
-
Run your
chemistry.py
program and ensure that your program’s output matches the following output. The three vertical dots (⋮) in the output below are called a vertical ellipsis and mean the output continues. Your program shouldn’t print the vertical ellipsis. Instead, your program should print the rest of the output.> python chemistry.py Actinium 227 Silver 107.8682 Aluminum 26.9815386 Argon 39.948 Arsenic 74.9216 Astatine 210 Gold 196.966569 ⋮
Submission
On or before the due date, return to Canvas and report your progress on this milestone.
Up Next
- W04 Prove: Chemistry
Other Links:
- Return to: Week Overview | Course Home