We have been asked to do quite a lot of calculations in this example so let's break it up into several smaller parts. To work out the concentrations in g/L and M after dilution, we need to first work out the concentrations in g/L and M of the "stock" solution. Let's start by working out the concentration of the "stock" solution in g/L.
The "stock" solution contains $\var{stock_mass}$g of sodium chloride dissolved in $\var{stock_volume}$L of solution. To work out the concentration in g/L we use the formula
$\dfrac{\text{mass of substance (in grams)}}{\text{volume of liquid (in litres)}} = \text{concentration (in g/L)}.$
Putting in our numbers we find that the concentration of the "stock" solution in g/L is
$\dfrac{\var{stock_mass}}{\var{stock_volume}} = \var{stock_mass / stock_volume} \text{ g/L}.$
Next, we can work out the concentration of the stock solution in M (mol/L). The formula for this is
$\dfrac{\text{number of moles of substance}}{\text{volume of liquid (in litres)}} = \text{concentration (in mol/L)}.$
We can see that we need to work out how many moles of sodium chloride (NaCl) there are in $\var{stock_mass}$g. The formula for this is
$\dfrac{\text{mass of substance (in grams)}}{\text{molecular weight}} = \text{number of moles}.$
We can see that to do this, we are going to need to work out the molecular weight of sodium chloride (NaCl). We have been told the atomic weights of each of the atoms in sodium chloride (NaCl) so we can do this by adding together the atomic weights of all the atoms to get the molecular weight which is
$1 \times \var{Na} + 1 \times \var{Cl} = \var{NaCl} \text{ Da}.$
We can now use this to work out how many moles of sodium chloride there are in $\var{stock_mass}$g using the formula above. Putting in the numbers we find that there are
$\dfrac{\var{stock_mass}}{\var{NaCl}} = \var{stock_mass / NaCl} \text{ moles}$
of sodium chloride in $\var{stock_mass}$g. We can now work out the concentration of the "stock" solution in M (mol/L). The formula is
$\dfrac{\text{number of moles of substance}}{\text{volume of liquid (in litres)}} = \text{concentration (in mol/L)}.$
We have $\var{stock_mass}$g of sodium chloride dissolved in $\var{stock_volume}$L of liquid and we have calculated that there are $\var{stock_mass / NaCl}$ moles of sodium chloride in $\var{stock_mass}$g. Putting these numbers into the formula we find that the concentration of the "stock" solution in M is
$\dfrac{\var{stock_mass / NaCl}}{\var{stock_volume}} = \var{stock_molarity} \text{ M}.$
Let's recap what we have calculated so far. We have worked out that the concentration of the "stock" solution in g/L is
$\var{stock_mass_concentration} \text{ g/L}$
and in M is
$\var{stock_molarity} \text{ M}.$
Since we are diluting $\var{stock_volume_used}$ml of the "stock" solution, we need to work out how much sodium chloride there is in $\var{stock_volume_used}$ml of the solution using the concentrations we have calculated. We need to work this amount out in both grams and moles, let's start with grams. If we rearrange the formula
$\dfrac{\text{mass of substance (in grams)}}{\text{volume of liquid (in litres)}} = \text{concentration (in g/L)}.$
we find that
${\text{volume of liquid (in litres)}} \times \text{concentration (in g/L)} = \text{mass of substance (in grams)}.$
Now, $\var{stock_volume_used}$ml is equal to
$\dfrac{\var{stock_volume_used}}{1000} = \var{stock_volume_used / 1000} \text{ L},$
so in $\var{stock_volume_used}$ml of "stock" solution, there are
$\var{stock_volume_used / 1000} \times \var{stock_mass_concentration} = \var{(stock_volume_used / 1000) * stock_mass_concentration} \text{ g}$
of sodium chloride. Similarly, we can work out the number of moles of sodium chloride using the formula
${\text{volume of liquid (in litres)}} \times \text{concentration (in mol/L)} = \text{number of moles of substance}.$
Putting in our numbers, we find that in $\var{stock_volume_used}$ml of "stock" solution, there are
$\var{stock_volume_used / 1000} \times \var{stock_molarity} = \var{(stock_volume_used / 1000) * stock_molarity} \text{ moles}$
of sodium chloride.
Finally, we can work out the concentration of the diluted solution. We know that $\var{stock_volume_used}$ml of "stock" solution is diluted to $\var{final_volume}$ml so the final volume of liquid is $\var{final_volume}$ml. We have worked out that in $\var{stock_volume_used}$ml of stock solution there are $\var{(stock_volume_used / 1000) * stock_mass_concentration}$g ($\var{(stock_volume_used / 1000) * stock_molarity}$ moles) of sodium chloride and we have not added any more sodium chloride so in our diluted solution we have $\var{(stock_volume_used / 1000) * stock_mass_concentration}$g ($\var{(stock_volume_used / 1000) * stock_molarity}$ moles) of sodium chloride in $\var{final_volume}$l of liquid. The formula for the concentration in g/L is
$\dfrac{\text{mass of substance (in grams)}}{\text{volume of liquid (in litres)}} = \text{concentration (in g/L)}.$
$\var{final_volume}$ml is equal to $\var{final_volume / 1000}$L and so the concentration of the diluted solution in g/L is
$\begin{align}\dfrac{\var{(stock_volume_used / 1000) * stock_mass_concentration}}{\var{final_volume / 1000}} & = \var{final_mass_concentration} \\ & = \var{precround(final_mass_concentration, 3)} \text{ g/L to 3 d.p.}\end{align}$
The formula for concentration in M (mol/L) is
$\dfrac{\text{number of moles of substance}}{\text{volume of liquid (in litres)}} = \text{concentration (in mol/L)}$
so the concentration of the diluted solution in M is
$\begin{align}\dfrac{\var{(stock_volume_used / 1000) * stock_molarity}}{\var{final_volume / 1000}} & = \var{final_molarity} \\ & = \var{precround(final_molarity, 3)} \text{ M to 3 d.p.}\end{align}$