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.
Enter temperature in degrees C: 10↵ At this temperature, the vapor pressure is approximately 12.2716959939 millibars
Here, what the computer prints is in regular font, what you type is in italic font, 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).
Call this program “vp.py”, and put your answer in a comment at the beginning of the program.
temp pressure ---- -------- -20 1.26 … 50 124.02with 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.
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:
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 π:
After 5 terms, the approximation is 3.1426047456630846Hint: Your number may differ; this is intended to show you the format of the output only.
Call your program ``sharp.py'', and put your answer to the second question in a comment at the beginning of the program.
ECS 10, Basic Concepts of Computing Fall Quarter 2012 |