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 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 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

Help from a 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:

  1. Using VS Code, create a new file and save it as chemistry.py
  2. In the chemistry.py file, write a function named make_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],
              ⋮
        ]
    
    1. 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.
    2. 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.
  3. In the chemistry.py file, write the main function that takes no parameters and returns nothing. The main function should do the following:
    1. Call the make_periodic_table function and store the returned list in a variable.
    2. Print the name and atomic mass for each chemical element on a separate line. Do not print the chemical element symbols.
  4. At the bottom of your chemistry.py file, add a call to the main function. Be certain to protect the call to main with an if statement 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:

  1. The computer starts executing the chemistry.py program by calling the main function.
  2. While executing the main function, the computer calls the make_periodic_table and print functions.
The call graph for a program that creates and prints a
        basic periodic table
The call graph for a program that creates and prints a basic periodic table.

Testing Procedure

Verify that your program works correctly by following each step in this testing procedure:

  1. Download the test_chemistry_1.py Python file and save it in the same folder where you saved your chemistry.py program. Run the test_chemistry_1.py file and ensure that the test_make_periodic_table function passes. If it doesn’t pass, there is a mistake in your make_periodic_table function. Read the output from pytest, fix the mistake, and run the test_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\lesson07
    collected 1 item
    
    test_chemistry_1.py::test_make_periodic_table PASSED  [100%]
    
    ==================== 1 passed in 0.14s =====================
  2. 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 I‑Learn and report your progress on this milestone.