Homework #1

 


Include your answers to all of these exercises in one document. You may copy and paste any code you write into your text document.

  1. Exercise: Write a function that will convert grams of a substance to moles. The function should get the weight of the substance in grams and the molecular mass of the substance as input from the user and then print out the number of moles of this substance.
    You may refer to the following website: http://www.chemteam.info/mole/Grams-to_Moles.html to help you with the formula to determine the number of moles of a substance.

    For example, in Problem #1 at the link above, we are given 25.0 grams of KMnO4, which has a molecular mass of 158.034 grams/mole. The resulting number of moles is 0.158 mol.
    There are several additional practice problems at that link that you can use to check that your function is working.

  2. Exercise: Write a new version of the function in the previous exercise that takes the weight of the substance and the molecular mass as parameters to the function and instead of printing out the number of moles, it returns the number of moles.
  3. Exercise: Discuss the advantages and disadvantages of using input statements versus using parameters to get values to use in a function.
  4. Exercise: Discuss the advantages and disadvantages of using a print statement to display results at the end of a function versus using a return statement to return the result of a function at the end.
  5. Exercise: Write up your answers to parts b and c of Exercise 4.8 from your text.

Submit