MCS-177 Project 1: Candy Temperatures (Spring 2014)

Start: Tuesday, 2/18; Due: Friday, 2/21, by the beginning of class


Overview

When you cook a sugar syrup to make candy, you have to heat it up to the appropriate temperature for the kind of candy, which can range from about 225°F for candied fruit to nearly 350°F for caramelized sugar. However, what really matters isn't the temperature, it is the way the sugar behaves, which depends on other factors than just the temperature. In particular, elevation above sea level is another factor. One solution to this problem is to test the behavior directly, for example by dropping a little of the syrup into cold water. But there is another solution that lets you use a candy thermometer: you have to adjust the temperature given in the recipe downward by 1°F for each 500 feet of elevation above sea level. In this project, you will write a Python procedure for calculating the adjusted temperature for a candy, given the recipe's temperature and the elevation in feet. You will also demonstrate how your procedure can be used to make a conversion table.

You are to do this project individually.

Specific tasks

  1. Open up a new window in Idle and type in a definition for a procedure, candyTemperature. The procedure should have two parameters, one for the recipe's temperature (in °F) and one for the elevation above sea level (in feet). Be sure to pick descriptive names for the two parameters. As an example, in the book's Listing 2.2, the archimedes procedure has one parameter named sides; this is a better choice than n because it serves as a reminder that the number specifies how many sides the polygon should have. Your procedure should return the adjusted temperature (in °F) that is appropriate to the specified elevation. If you choose to break the calculation into steps and give names to the intermediate values (as in Listing 2.2), be sure to continue using meaningful names. Save your program in a file called candy.py.

  2. Use Idle's "Run Module" command from the Run menu, or equivalently press the F5 key. If Idle reports any syntax errors in your program, fix them. When you get past that hurdle, use the Python Shell window of Idle to try your candyTemperature procedure out. Specifically, use it to calculate the temperature for chocolate caramels in Denver, based on the following information. A recipe in the Joy of Cooking that says chocolate caramels should be cooked to 244°F. Denver is known as the "mile high city," which means its elevation ought to be 5280 feet. Whenever you test a program, you should figure out what would constitute success. That means you ought to figure out the correct adjusted temperature so you have something to compare with. Notice that 5280 feet is between 10 and 11 times 500. Use that to figure out which two integers (in °F) the correct answer must be between. Make sure your procedure gives an answer in that range; if not, fix it.

  3. Because candy thermometers are normally calibrated just in integer degrees, it would be convenient if your procedure returned an answer that was rounded off to the nearest integer. Python has a procedure for doing the rounding. For example, round(2.4) evaluates to 2, whereas round(2.6) evaluates to 3. Modify your program by inserting an appropriate invocation of the round procedure so that the answer is guaranteed to be an integer. Test that candyTemperature now gives a correct integer temperature for cooking chocolate caramels in Denver. Also, perform another test of your own devising to make sure your procedure gives an integer answer even if the recipe's temperature is not an integer.

  4. Use a for loop to print out a conversion table for use in Denver. The first column of the table should show recipe temperatures ranging from 225°F up to, but not including, 350°F, stepping by 5°F each row. The second column of the table should show the corresponding adjusted temperature, calculated using candyTemperature. Any name(s) you choose should be descriptive. Be sure to check your results; the pattern is simple enough to make the results straightforward to confirm.

Submitting your work

You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following 3 files (with the following recommended names):

Grading

You will earn one point for each of the following accomplishments:

  1. You used the correct notation to define a procedure called candyTemperature.

  2. The procedure has two parameters.

  3. The procedure's first parameter's name is descriptive.

  4. The procedure's second parameter's name is descriptive.

  5. The procedure's intermediate values' names (if any) are descriptive.

  6. The procedure returns an answer.

  7. The procedure correctly calculates the adjustment.

  8. The procedure correctly applies the adjustment to the temperature.

  9. The procedure correctly rounds its answer to an integer.

  10. You have avoided unnecessary complexity in the procedure. For example, you have not performed two conversions that cancel each other out or included any code that doesn't affect the answer. You should make good use of features built in to Python rather than building equivalent functionality yourself.

  11. You have correctly shown the example of chocolate caramels in Denver.

  12. You have used a for loop to range over temperatures.

  13. Any name you used in the loop is descriptive.

  14. The starting temperature for the loop is correct.

  15. The ending temperature for the loop is correct.

  16. The step size for the loop is correct.

  17. The body of loop prints two columns.

  18. The body of loop prints the correct data.

  19. The body of loop uses candyTemperature.

  20. You have avoided unnecessary complexity in the loop.