Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In chemistry, a mole is a very large, fixed quantity, specifically 6 0 2 , 2 1 4 , 0 7 6 , 0 0
In chemistry, a mole is a very large, fixed quantity, specifically usually written as times 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 HO water or CHOglucose
The mass in grams of a sample of the substance, such as
The calculator computes the molar mass of the molecule by doing the following for each element in the formula:
Sum the number of atoms of each element in the formula
Find the atomic mass of each element
Multiply the number of atoms by their atomic mass
Add the product into the molar mass of the molecule
Then the calculator computes the number of moles in the sample with this formula:
numberofmoles
samplemass
molarmass
Finally, the calculator prints two results for the chemist to see:
the molar mass
the number of moles
Example
As an example, consider a sample of glucose CHO with a mass of grams. To use a molar mass calculator, a chemist enters
CHO
The calculator computes the molar mass of glucose by doing the following:
Sum the number of atoms of each element in the formula for glucose:
carbon atoms
hydrogen atoms
oxygen atoms
Find the atomic mass of each element:
Symbol Name Atomic Mass
C Carbon
H Hydrogen
O Oxygen
Multiply the number of atoms by their atomic mass:
times
times
times
Add the results of the multiplications to get the molar mass of glucose:
gramsmole
Then the calculator divides the mass of the sample of glucose by the molar mass of glucose which results in the number of moles in the sample:
grams
gramsmole
moles
The calculator prints two results for the chemist to see:
the molar mass of glucose: gramsmole
the number of moles in the sample: moles
Assignment
During this assignment, you will write and test the remaining parts of the molar mass calculator that you started writing in the previous lessons prove milestone. When you are finished with this prove assignment, your chemistry.py program must contain at least three functions named as follows:
main
makeperiodictable
computemolarmass
Helpful Documentation
The prove milestone explains how a molar mass calculator should work.
The preparation content explains how to create and use a dictionary in a Python program.
The preparation content for week explains how to use pytest, assert, and approx to automatically verify that functions are correct. It also contains an example test function and links to additional documentation about pytest.
Download the formula.py Python file and save it in the same folder where you saved your chemistry.py program from the previous prove milestone. The formula.py file includes a FormulaError class and a function named parseformula. Both of them are complete and work correctly, and you should not change them.
Open the formula.py file in VS Code and read the triple quoted string at the top of the parseformula function. As the triple quoted string states, the parseformula function converts a chemical formula for a molecule, such as CHNOmelatonin into a compound list, such as CHNO This compound list is known as a symbolquantitylist because it contains the symbols of chemical elements and the quantity of atoms of each element that appear in a chemical formula.
Copy and paste the following import statement into your chemistry.py program at the top of your program. This statement will import the parseformula function from the formula.py file into your chemistry.py program so that you can call the parseformula function in your program.
from formula import parseformula
In your chemistry.py program, change the compound list that is in your makeperiodictable function to a compound dictionary. Each item in the dictionary should have a chemical symbol as the key and the chemical name and atomic mass in a list as the value, like this:
periodictabledict
# symbol: name atomicmass
Ac: Actinium
Ag: Silver
Al: Aluminum
We strongly recommend that you use find and replace or multiline editing in VS Code to quickly change the periodic table to a compound dictionary. If you don't know how to use find and replace or multiline editing, ask a fellow student, a tutor, a teaching assistant, or your teacher for help.
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started