Now You Code 4: Temperature Conversion

Part 1

Write a Python program to input a temperature in Fahrenheit or Celcius, then converts it to the other unit. The program should first input a temperature then input a unit of C or F. It should then convert the temperature to the other unit.

After you get it working initially, re-write it to handle bad input.

Example Run 1:

    Enter temperature: 212
    In which units is that: C or F? F
    That's 100.0 C

Example Run 2:

    Enter temperature: 0
    In which unit is that: C or F? C
    That's 32.0 F

NOTE: You can find the formulas online.

Step 1: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [1]:
#Step 2: write code here

Part 2

Now that you have it working, re-write your code to handle bad input using Python's try... except statement. When the exception occurs, you can just print the message and exit the program.

Example run:

    Enter temperature: wicked hot
    Sorry, that's not a temperature I can convert.

Note: Exception handling is not part of our algorithm. It's a programming concern, not a problem-solving concern!


In [1]:
## Step 2 (again): write code again but handle errors with try...except

Step 3: Questions

  1. What specific Python Error are we handling (please provide the name of it)?

Answer:

  1. How many times must you execute this program before you can assume its correct? Explain.

Answer:

  1. What happends when you enter a lower-cased 'f' or 'c' does it work? Does it work with both upper and lower cased values? How can we make it work?

Answer:

  1. What happens when you enter a value other than 'F' or 'C' for the units. If you don't like the result, how can you modify the program to handle this issue?

Answer:

Step 4: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--