Input and Output
Programs read input and print output.
About this topic
Input is data that a program receives, from a keyboard, mouse, file, sensor or network, and output is the data it produces, such as text on the screen, a saved file or a sound. Almost every useful program takes input, processes it and gives output.
In Python, input() reads text typed by the user and print() displays results. Input usually arrives as a string, so numbers must be converted, for example age = int(input()), before doing maths. Files add permanence: a program can open a file, read lines, write results and close it so data survives after the program ends.
A simple program might ask for your name and greet you, or read a file of test scores and print the average. Websites do the same with forms and responses. A common error is forgetting to convert input, so 5 plus 3 gives 53 instead of 8. Another is not validating input, letting a user type letters when numbers are needed, which can crash the program. Always check and clean what users give you and give clear prompts and messages.
Key ideas
- input() reads text
- print() shows results
- Files and streams
Quick check
Use cases: where Input and Output helps
- Homework: review the key idea behind Input and Output before you start a problem set.
- Exam revision: use the quick check to test whether you can recall Input and Output without notes.
- Visual learning: play with the interactive lab to see how Input and Output changes when you adjust its inputs.
- Teaching a friend: explain Input and Output in your own words, then compare your version with the key ideas.
Computing ideas run phones, search engines, games and the wider internet.
Frequently asked questions
What is Input and Output?
Programs read input and print output.
What will I learn in Input and Output?
input() reads text. print() shows results. Files and streams.
Is Input and Output part of Computer Science?
Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.
Does the Input and Output lab work on a phone or tablet?
Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.
How should I study Input and Output?
Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.
Do I need an account, and is my progress saved?
No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.