2.2 Input, Processing, and Output — Python Basics

Input

  • Input is data that the program receives.
  • A program, during execution, receives data which is referred to as input.
  • One common form of input is data typed on the keyboard.
  • After input is received, some process is performed on it.

Processing

  • Processing is the execution of some operation on the input data.
  • The result of this operation is the program’s output.
  • The general three-step flow is: Input -> Processing -> Output.
  • The relationship: Input is data, Processing is the operation applied to that data, Output is the resulting data produced.

Output

  • Output is the result that comes from the processing step and is sent out of the program.
  • In the pay calculation example, the output is what is displayed as the result on the screen.
  • The act of producing output completes the I/O cycle for that operation.

Three-step model of a program

  • Step 1: Input is received.
  • Step 2: Some process is performed on the input.
  • Step 3: Output is produced.
  • This sequence is the standard model for simple programs.
  • The same three steps are illustrated by the pay calculation example: input hours worked and hourly pay rate, process by multiplication, output the result.

Pay calculation example (input, processing, output)

  • Input: hours worked and hourly pay rate are provided as input.
  • Processing: multiply the hours worked by the hourly pay rate.
  • Output: the result is displayed on the screen.
  • Mathematical representation of the processing step:
    \text{Output} = \text{hours} \times \text{hourly_pay_rate}
  • This example demonstrates how data flows through input, processing, and output.
  • The narrative references Figure 2-3, which illustrates these three steps in the pay calculating program.

Python context

  • This chapter introduces basic ways to perform input, processing, and output using Python.
  • The emphasis is on understanding the I/O trio as a foundation for writing Python programs.

Connections and implications

  • The input, processing, and output model is foundational to almost all programming tasks.
  • Correct input handling is crucial for meaningful and reliable output.
  • The simplicity of the pay example helps in understanding how data types (numbers for hours and rate) are combined through a basic operation (multiplication) to yield a result.

Quick recap

  • Input: data received by the program (e.g., keyboard input).
  • Processing: perform an operation on the input (e.g., multiplication).
  • Output: present the result (e.g., display on screen).
  • Real-world example: calculating pay using hours and hourly rate with the relation \text{Output} = \text{hours} \times \text{hourly_pay_rate} .