Due: Friday, October 12, 2012 at 5:00PM | Points: 100 |

Please turn in your answers for the homework assignment on SmartSite, under Homework #1 in Assignments. Turn in your programs answers for the extra credit under Extra Credit #1 there.

- (
*30 points*) Write a program that asks the user for the temperature*t*in degrees Celsius and then displays the estimated vapor pressure of water vapor in millibars at that temperature using the approximationEnter temperature in degrees C:

*10*↵ At this temperature, the vapor pressure is approximately 12.2716959939 millibarsHere, what the computer prints is in

`regular font`, what you type is in, and the symbol “↵” represents a return or enter. Use your program to estimate the temperature at which the vapor pressure is approximately 10 millibars (to two decimal places).*italic font*Call this program “vp.py”, and put your answer in a comment at the beginning of the program.

- (
*40 points*) Modify the program you wrote for question 1 to print the estimated vapor pressures for temperatures between −20 and 50 degrees Celsius at 5 degree intervals. Your output should look like this:temp pressure ---- -------- -20 1.26 … 50 124.02

with the proper numbers substituted for the “…”s (so you need only compute the vapor pressure to 2 decimal places). Call this program “vptable.py”.*Hint*: One way to print the table is to use the format string “`"%3d\t%6.2f" % (i , vp(i))`”, where`i`is the temperature and`vp(i)`is the function to compute the vapor pressure from the temperature`i`. - (
*40 points*) The goal of the following program is to convert a temperature from degrees Farenheit to degrees Celsius. The formula is:*F*is the number of degrees Fahrenheit and*C*the number of degrees Celsius.Here is the program:

ftemp = input("Enter degrees in Fahrenheit: ") ctemp = 5 // 9 * (ftemp - 32) print(ftemp, "degrees Fahrenheit is", ctemp, "degrees centigrade")

But there are two problems:

- Whenever I run the program, it gives me a TypeError message as soon as I enter my number.
- Once I fixed this problem, it always tells me the result is −0.0 degrees Celsius.

Please fix both these problems, so the program converts Fahrenheit to Celsius correctly. The program must handle floating point numbers, so entering “32.5” should produce a (small) real number, not a ValueError.

Call your fixed program “ftoc.py”, and explain what caused the two problems in a comment at the beginning of the program.

Remember to hand this in under Extra Credit #1, *not* under Homework #1!

Abraham Sharp developed an infinite sum that produces π:

- (
*20 points*) Compute and print the resulting approximations to π for the first 5, 10, …, 50 terms. Each line of your output should look like this:After 5 terms, the approximation is 3.1426047456630846

*Hint*: Your number may differ; this is intended to show you the format of the output only. - (
*10 points*) After what term does adding extra terms stop improving the approximation?

Call your program ``sharp.py'', and put your answer to the second question in a comment at the beginning of the program.

A PDF version is available here.

ECS 10, Basic Concepts of Computing Fall Quarter 2012 |