07 Prove Milestone: Lists
Purpose
Prove that you can write a Python program that creates and uses a compound list.
Problem Statement
In chemistry, a mole is a huge quantity of atoms or molecules, specifically 602,214,076,000,000,000,000,000 (usually written as 6.02214076 × 1023), which is more than 602 sextillion. For example, a mole of carbon atoms is a sample of carbon that contains 6.02214076 × 1023 atoms. A mole of water molecules is a sample that contains 6.02214076 × 1023 molecules of water.
The molar mass of a substance is the mass in grams of one mole of the substance (grams / mole). For example, the molar mass of carbon is 12.0107 grams / mole. If you collect one mole (6.02214076 × 1023 atoms) of carbon, the total mass will be 12.0107 grams. If you collect one mole (6.02214076 × 1023 molecules) of water, the total mass will be 18.0153 grams.
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 substance (molecule), such as H2O (water) or C6H12O6 (glucose)
- The mass of a sample of that substance, such as 3.71 grams
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 that exist 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 existing
elements.
Help
If you’re having trouble completing this assignment, reading related online documentation, using a generative AI as a tutor, or working with a human tutor will help you complete it.
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 lesson explains how to create and use a compound list.
- The preparation content for lesson 5 explains how to use
pytest,assert, andapproxto automatically verify that functions are correct. It also contains an example test function and links to additional documentation aboutpytest.
Help from an AI Tutor
You can use a generative AI as a tutor to help you write and troubleshoot your program. Bro. Lee Barney created a custom Chat GPT named Pythonista that is designed to focus on Python functions, loops, if statements, and related programming concepts. If your program is generating an error, ask Pythonista a question like this:
I'm writing a Python program that computes the molecular mass and number of moles of a chemical sample. When I run my program, it causes the following error. Please suggest some mistakes that might cause this error.
(Copy and paste the error message here.)
You could also ask Pythonista a question about one of your functions, like this:
I wrote the following Python function that is supposed to (type a short description here). However, the function isn't (type what it's not doing correctly here). Please help me fix this function.
(Copy and paste your Python function here.)
Help from a Human Tutor
As a BYU-Idaho campus or online student you can get help from a tutor to complete your CSE 111 assignments. Each tutor is a current BYU-Idaho student employed by BYU-Idaho. 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. Campus students meet with tutors in the tutoring center. Online students meet with tutors in Zoom. To make an appointment, follow the instructions in the course tutoring guide.
Steps
Do the following:
- Using VS Code, create a new file and save it as
chemistry.py - In the
chemistry.pyfile, write a function namedmake_periodic_tablethat 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_tablefunction, 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.pyfile, write themainfunction that takes no parameters and returns nothing. Themainfunction should do the following:- Call the
make_periodic_tablefunction 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.pyfile, add a call to themainfunction. Be certain to protect the call tomainwith anifstatement as taught in the preparation content for lesson 5.
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
chemistry.pyprogram by calling themainfunction. - While executing the
mainfunction, the computer calls themake_periodic_tableandprintfunctions.
Testing Procedure
Verify that your program works correctly by following each step in this testing procedure:
- Download the
test_chemistry_1.pyPython file and save it in the same folder where you saved yourchemistry.pyprogram. Run thetest_chemistry_1.pyfile and ensure that thetest_make_periodic_tablefunction passes. If it doesn’t pass, there is a mistake in yourmake_periodic_tablefunction. Read the output frompytest, fix the mistake, and run thetest_chemistry_1.pyfile 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\lesson07 collected 1 item test_chemistry_1.py::test_make_periodic_table PASSED [100%] ==================== 1 passed in 0.14s =====================
- Run your
chemistry.pyprogram 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 I‑Learn and report your progress on this milestone.