Input Process Output (IPO) Model

You have seen the Input-Process-Output model in action. Conceptually, it looks like this:

images/input-output.png

  1. Input is provided when the program starts to run
  2. The input is processed
  3. Output is produced

The PyCharm IDE starts execution of the program when you click the Run command (green) triangle, and the Python runtime, which kicks off the program, finds the beginning of the main routine, or function: if __name__ == "__main__":

When the program starts to run, it follows the instructions you coded into your program. If you can, you should request and provide all input at the beginning of program execution, and provide all output at the end. Intermediate results can be stored as variables in memory along with the inputs.

Let’s consider another program that converts temperatures between Fahrenheit and Celsius.

First ask yourself what inputs does my program need. If you answered a number that represents a temperature in Fahrenheit, you are right.

What is the output? The temperature in Celsius.

So, what is the process?

  1. Request a value [the input]
  2. Convert the value using the formula C = (5/9) * (F - 32) [the process]
  3. Display the new value [the output]

What variables are needed?

How do you decide what to name a variable? As a best practice, variable names should, most importantly, reflect on the usage of the variable; they should be lowercase, with words separated by underscores as necessary to improve readability. Thus, 'in' and 'out' are short forms for input and output, and 'temp' is a shortened form meaning temperature. You could have chosen input_temperature and output_temperature, but these names seem a bit long, and since there are no temporary things in the program to confuse the word 'temp' with, using 'temp' to mean temperature seems okay, too. If you want a much more complete but longer answer, see the Naming Conventions section of the Python Style Guide

We will see later that there are other ways to write even such a simple program as this one, but for now, we can use an extra variable it is a bit more clear what the program is doing.

A Few Notes About Variables and Data Types

Consider the statement: print(str(in_temp)+"F"+" = "+str(out_temp)+"C"). If you look up the print function in documentation, you will see that it only prints a single string. A String is a data type. Thus, all the numbers must be converted to strings and they must be concatenated (strung together) to form one string. The + operator is the concatenate operator for strings. For numbers, the + operator is the addition operator, which adds 2 numbers together, as in z = 2 + 3 resulting in z containing the value 5.

You can specify a the value of a string by surrounding it with quotes, either double quotes or single quotes; they are interchangeable for reasons to be discussed later. (The print statement above could also be written as print(str(in_temp)+'F'+' = '+str(out_temp)+'C').) Thus, you can tell the difference between a string that contains the characters "10" from the number 10, because the number is not surrounded by quotes. As you saw earlier, to convert an integer number to a string, you use the int() function. You use the str() function to convert a number to a string.

Assignment

  1. Create a new project, ConvertTemp, which you will use in subsequent assignments
  2. Collect the temperature in Fahrenheit (If you didn’t do the extra credit from the last assignment, put a "label" in your input statement, e.g. input("Enter F: ")
  3. Convert it to Celsius
  4. Display the result using the following statement:
    print(str(in_temp)+"F"+" = "+str(out_temp)+"C")
  5. Test your program against some Fahrenheit temperatures that you know the conversion for, e.g. the freezing and boiling points for water, 32 and 212
  6. Submit a screen shot of your running program code
  7. Read Python Variable Names and answer the following question: When the coding style requires that variable names "should be lowercase, with words separated by underscores as necessary to improve readability," what is the name of this style?