CS105: Computer Programming: PYTHON Project 01 Assigned on Monday, Sept. 10, 2007 Due on Monday, Sept. 17 at 11:59PM ============= 1. Objectives ============= Last week, we learned basic concepts and procedures for us to get ready for programming in PYTHON. Through this project, we want to have time to review what we have learned in the class. ============== 2. Description ============== We start with a simple code, but modify it step by step. At each step, We'll be asked some questions that double-check our understanding. After going through all the requests, we'll have a complete code. - Let's start with the following code def main(): celsius = input("What is the Fahrenheit temperature? ") fahrenheit = 9 / 5 * celsius + 32 print "The temperature is', fahrenheit,, "degrees Fahrenheit." main() ------------------------ (QUESTION 01): 10 points ------------------------ List ways of running this script. ==> ------------------------ (QUESTION 02): 10 points ------------------------ Is it working fine as it is? There are three bugs in the code, so correct them. ==> ------------------------ (QUESTION 03): 10 points ------------------------ After debugging, comment out the last line, "main()", and explain what happens when you try to run it. ==> ------------------------ (QUESTION 04): 10 points ------------------------ Now, change "def main()" to "def celsius2Fahrenheit()" and "main()" to "celsius2Fahrenheit()". Try to run it as you do in (QUESTION 02) or (QUESTION 03). Explain why? ==> ------------------------------ (IMPLEMENTATION 01): 10 points ------------------------------ A user-friendly program should print an introduction that tells the user what the program does. So, add a function (say "printIntroduction()") that prints out the following message upon running your python script: ==> e.g. > convertTemperature.py This program converts Celsius to/from Fahrenheit temperature. What is the Celsius temperature? 100 ......... ==> So, you need to define and call the following function: def printIntroduction(): ???? ------------------------------ (IMPLEMENTATION 02): 10 points ------------------------------ Implement a function that takes a Celsius and returns a corresponding Fahrenheit. ==> def c2f(celsius): ------------------------------ (IMPLEMENTATION 03): 10 points ------------------------------ Implement a function that prints a table of Celsius temperatures and the Fahrenheit equivalents every 20 degrees from 0C to 100C. ==> You'll call "c2f(celsius)" you defined in (IMPLEMENTATION 02) from the following function: def printTable_c2f(): ------------------------------ (IMPLEMENTATION 04): 10 points ------------------------------ Write a program that converts from Fahrenheit to Celsius. ==> fahrenheit2Celsius(): ------------------------------ (IMPLEMENTATION 05): 10 points ------------------------------ Implement a function that takes a Celsius and returns a corresponding Fahrenheit. ==> def f2c(fahrenheit): ------------------------------ (IMPLEMENTATION 06): 10 points ------------------------------ Implement a function that prints a table of Fahrenheit temperatures and the Celsius equivalents every 20 degrees from 200F to 100F. ==> You'll call "f2c(fahrenheit)" you defined in (IMPLEMENTATION 05) from the following function: def printTable_f2c(): ============================== 3. Grading criteria and policy ============================== Please make sure to include the followings at the header of the code. In summary, "convertTemperature.py" should contain AT LEAST the followings: -------------------------------------------------------------------- # Project: 01 # Description: Convert temperature (Celsius <-> Fahrenheit) # Program: convertTemperature.py # Input: NONE # Output: NONE # Usage: ./convertTemperature.py # Name: Your name # UT EID: Your EID # Comments (or README): # Describe what you with to grader to know. # e.g., What did you like/dislike about this project? # What was the most challenging in this project? # etc. def printIntroduction(): ......... def c2f(celsius): ......... def f2c(fahrenheit): ......... def celsius2Fahrenheit(): ......... def fahrenheit2Celsius(): ......... def printTable_c2f(): ......... def printTable_f2c(): ......... ------------------------------------------------------------ ================== 4. Running example ================== The followings are expected upon running the complete script: -------------------------------------------------------------- > ./convertTemperature.py This program converts Celsius to/from Fahrenheit temperature. What is the Celsius temperature? 100 The temperature is 212.0 degrees Fahrenheit. What is the Fahrenheit temperature? 212 The temperature is 100.0 degrees Celsius. celsius fahrenheit 0.0 32.0 20.0 68.0 40.0 104.0 60.0 140.0 80.0 176.0 100.0 212.0 fahrenheit celsius 200.0 93.3333333333 180.0 82.2222222222 160.0 71.1111111111 140.0 60.0 120.0 48.8888888889 100.0 37.7777777778 > ----------------------------------------------------------- ======= 5. NOTE ======= This project is worth a total of 100 points. We'll discuss details about the project in the class. Submit two files, "answer01.txt" and "convertTemperature.py", as follows: > turnin --submit hyukcho project01 answer01.txt convertTemperature.py Good luck!