Input and Output in Programming

► Overview

Input and output (I/O) are fundamental concepts in programming. Input is data that a program receives from the user or other sources, while output is data that the program sends back to the user or other destinations.

► Real-World Analogy

Think of a program like a vending machine:
» You input money and make a selection (input)
» The machine processes your request
» You receive your chosen item (output)
» Every interaction involves input and output

► Key Concepts

✓ Input: Data entered by the user (keyboard, file, sensor)
✓ Output: Data displayed by the program (screen, file, printer)
✓ Standard Input (stdin): Default input source (keyboard)
✓ Standard Output (stdout): Default output destination (screen)

■ Input Example

Getting data from the user:

/code

Getting input from user

name = input(“Enter your name: “)
age = input(“Enter your age: “)

print(“Hello,”, name)
print(“You are”, age, “years old”)

Output:
Enter your name: Alice
Enter your age: 25
Hello, Alice
You are 25 years old

► Important Points

✓ input() function always returns a string
✓ Use int() or float() to convert input to numbers
✓ print() function displays output to the screen
✓ Multiple values can be printed with commas

► Remember

✓ Every interactive program needs input and output
✓ Always validate user input for errors
✓ Use meaningful prompts for input
✓ Format output for better readability

■ Practice Challenge

  1. Create a program that asks for two numbers and prints their sum
  2. Get user’s name and age, then calculate birth year
  3. Create a simple calculator with input and output