CPSC120 Lab 2

Naming, Functions, and Testing

For each of the following excercies do the following in order:

  1. Read the entire excercise specification.
  2. Create test a test function. Test function should print both the actual and expected output for a particular input.
  3. Write the function, including the function comment with a description, pre-condition, and post-condition.
  4. Verify the function works by running the test function.

1. Light Years

Create a function called `compute_years_to_star` in a file called
`years.py`.  The function should return the number of years it
would take to get to a star given the distance to the star (in
light-years) and the rate of travel (in miles per hour).  Assume
that a light year is $5.878 x 10^12$ miles.
  1. Paint Volume

    Create a function called calculate_paint_volume in a file called paint.py. The function should return the number of gallons of paint that are required to paint walls of rectangular room given the length, width, and height of the room in feet. Assume that the floor and ceiling will also be painted and that paint can cover 350 square feet of wall per gallon. The number of gallons should be a real number.

  2. Change

    Create a function called print_change in a file called change.py. The function should return the smallest number of coins (quarters, dimes, nickles, and pennies) equivalent to the specified number of cents.


Submit a zip file of your code on the course Inquire site that uses your last names as the file name.