Question: Copy and paste the following Python code into your chemistry.py program. Be certain not to paste the code inside an existing function. # Indexes for
Copy and paste the following Python code into your chemistry.py program. Be certain not to paste the code inside an existing function.
# Indexes for inner lists in the periodic table NAME_INDEX = 0 ATOMIC_MASS_INDEX = 1 # Indexes for inner lists in a symbol_quantity_list SYMBOL_INDEX = 0 QUANTITY_INDEX = 1 def compute_molar_mass(symbol_quantity_list, periodic_table_dict): """Compute and return the total molar mass of all the elements listed in symbol_quantity_list. Parameters symbol_quantity_list is a compound list returned from the parse_formula function. Each small list in symbol_quantity_list has this form: ["symbol", quantity]. periodic_table_dict is the compound dictionary returned from make_periodic_table. Return: the total molar mass of all the elements in symbol_quantity_list. For example, if symbol_quantity_list is [["H", 2], ["O", 1]], this function will calculate and return atomic_mass("H") * 2 + atomic_mass("O") * 1 1.00794 * 2 + 15.9994 * 1 18.01528 """ # Do the following for each inner list in the # compound symbol_quantity_list: # Separate the inner list into symbol and quantity. # Get the atomic mass for the symbol from the dictionary. # Multiply the atomic mass by the quantity. # Add the product into the total molar mass. # Return the total molar mass. return The code that you pasted includes the header and documentation string for a function named compute_molar_mass. Read the docstring and comments in the compute_molar_mass function and write the code for that function. Note that you can complete the compute_molar_mass function by writing ten or fewer lines of code.Modify the main function in your chemistry.py program so that it does the following:
def main(): # 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 periodic table in a variable. # Call the parse_formula function to convert the # chemical formula given by the user to a compound # list that stores element symbols and the quantity # of atoms of each element in the molecule. # Call the compute_molar_mass function to compute the # molar mass of the molecule from the compound list. # Compute the number of moles in the sample. # Print the molar mass. # Print the number of moles.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
