A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Basic Input and Output

College Depth 72 in the knowledge graph I know this Set as goal
592topics build on this
321prerequisites beneath it
See this on the map →
Variables and AssignmentPrimitive Data Types+2 moreFile I/O BasicsFile System Concepts+1 more
I/O print input console user interaction

Core Idea

Programs communicate with users through input and output operations. Output (e.g., print) sends text or values to the console; input (e.g., input() or scanf) reads text typed by the user. All console input arrives as text (strings), so numeric input must be converted to the appropriate type before arithmetic. Clear, informative output is a form of program documentation for the user.

How It's Best Learned

Write interactive programs that prompt for input, compute something, and display results. Deliberately forget type conversion and observe the resulting error.

Common Misconceptions

Explainer

You already know how to store data in variables and work with different data types. Input and output (I/O) are how your program communicates with the outside world — specifically, how it displays results to the user and receives data from them. Without I/O, a program computes in silence: it might calculate the answer to a problem, but no one would ever see it.

Output is the simpler side. In Python, `print()` sends text to the console. In C, `printf()` does the same. You can output literal strings (`print("Hello")`), variable values (`print(x)`), or combinations using string formatting or concatenation. The key idea is that output converts your program's internal data into a human-readable text representation. When you print an integer, the language converts the binary number in memory into a sequence of digit characters on screen. This conversion happens automatically for basic types, but understanding that it occurs helps you troubleshoot when output looks unexpected.

Input is where most beginners encounter their first surprising bug. When a user types `42` at the keyboard, the program receives the *string* `"42"` — two characters, not a number. This is because the console deals exclusively in text. If you want to do arithmetic with that value, you must explicitly convert it: `int("42")` in Python, `atoi()` or `scanf("%d", ...)` in C. Forgetting this conversion is the single most common I/O mistake. Your program will either crash with a type error or silently produce wrong results by concatenating strings instead of adding numbers. The rule is simple: all console input arrives as text, and you are responsible for parsing it into the type you need.

Good I/O also means writing clear prompts that tell the user what to type. A prompt like `"Enter your age: "` (with a trailing space) is far better than a blank cursor that leaves the user guessing. Think of output as your program's voice and input as its ears — together they create the conversation between human and machine. As you progress, you will learn to read from files and network connections, but the console I/O patterns you build now — prompt, read, convert, compute, display — are the foundation for all interactive programming.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesType Systems and Type SafetyType Conversion and CastingBasic Input and Output

Longest path: 73 steps · 321 total prerequisite topics

Prerequisites (4)

Leads To (3)