DoAssignment study guide
A2.1 · Write a program with input, processing, and output
Learn to write a program with input, processing, and output through clear examples and targeted practice.
Ontario Grade 11 Computer Science
Programming Concepts and Skills
A practical structure for small Python programs | ICS3U study topic A2.1
What you will learn
- Describe input, processing, and output in a simple program.
- Identify what information a program receives, what it does with that information, and what result it presents.
- Trace values through a short program to derive its expected output.
The three parts of a program
- Input: information received by the program.
- Processing: work performed on the information.
- Output: information presented as a result.
- Python 3 input() returns text; convert text before using it as a number.
Plan the data and trace the steps
- State what each input represents before tracing the program.
- Follow each assignment in order and update the variable's value.
- Derive output from the traced values; do not treat an expected result as a run result.
Check that the program meets its purpose
- Match the inputs, processing, and output to the task.
- Check calculations and readable output by tracing the stated values.
- A calculated value must be presented if the user is meant to see it.
Trace for the perimeter example
| Program point | length | width | perimeter |
|---|---|---|---|
| After input | 8 | 3 | not assigned |
| After calculation | 8 | 3 | 22 |
| Displayed result | 8 | 3 | 22 |
Trace for the points example
| Program point | first | second | total |
|---|---|---|---|
| After input | 14 | 17 | not assigned |
| After addition | 14 | 17 | 31 |
| Displayed result | 14 | 17 | 31 |
Worked example
Personalized greeting
The name is received, combined with greeting text, and displayed.
Python 3
name = input("Enter your first name: ")
greeting = "Hello, " + name + "!"
print(greeting)- Identify the inputThe input is the text the user types: Maya. The input() prompt asks for a name, and the typed text is stored in the variable name.
- Trace the processingThe program joins the greeting text, the name, and the exclamation mark. The spaces included in the text keep the words separated.
- Determine the outputThe resulting text is passed to print(), so the expected displayed line is Hello, Maya! This is derived from the stated input and code, not from an execution.
Worked example
Calculate a rectangle's perimeter
Two whole-number inputs are used in a calculation and its result is displayed.
Python 3
length = int(input("Length: "))
width = int(input("Width: "))
perimeter = 2 * (length + width)
print("Perimeter:", perimeter)- Receive numeric inputsEach input() first provides text. int() converts the digit text to a whole-number value so the program can perform arithmetic.
- Calculate the perimeterThe code adds the length and width, then multiplies that sum by 2. With the stated values, the sum is 11 and the perimeter is 22.
- Display the resultThe print() line displays the label followed by the perimeter value. The expected output is Perimeter: 22.
Worked example
Find the total points
Two inputs are added, then the resulting total is presented.
Python 3
first = int(input("Points from activity 1: "))
second = int(input("Points from activity 2: "))
total = first + second
print("Total points:", total)- Identify the two inputsThe program asks for points from activity 1 and activity 2. The int() conversion makes each entered whole-number value available for addition.
- Update the totalThe variable total receives the sum of the two inputs. Adding 14 and 17 gives 31, so total now stores 31.
- Trace the outputThe final line displays the words Total points: and the value stored in total. The expected output is Total points: 31.
Common mistakes and how to avoid them
Lesson summary
- Input is information the program receives; processing is work on that information; output is the result it presents.
- In Python 3, input() receives text. Convert suitable digit text with int() before whole-number arithmetic.
- Trace each assignment from top to bottom to determine the expected output without claiming the code was run.
- Check that the program receives what it needs, processes it as intended, and presents the requested result.
Check your understanding
Question 1
- It converts suitable digit text into a whole-number value.
- It displays the length on the screen.
- It adds the length to the width automatically.
- correctIndex: 0,
Show answer and explanation
Question 2
- 21
- 912
- 3
- correctIndex: 0
Show answer and explanation
Question 3
- Input
- Processing
- Output
- correctIndex: 2
Show answer and explanation
Key terms
- Input
- Information a program receives.
- Processing
- Work a program performs using information.
- Output
- Information or a result the program presents.
- Variable
- A named place in a program where a value can be stored.
- Trace
- A step-by-step record of values as a program's instructions are considered.
Continue through ICS3U
View the complete ICS3U Ontario Grade 11 Computer Science curriculum and lessons
- A1.6 · Create and update one-dimensional arrays in a program
- A2.2 · Use sequence, selection, and repetition
- A1.1 · Use variables and constants with appropriate data types
- A1.2 · Explain binary, hexadecimal, and character encoding
- A1.3 · Use arithmetic and string assignment statements
- A1.4 · Use Boolean, comparison, and arithmetic operators correctly
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 11 Computer Science (ICS3U), expectation A2.1. It is a study resource, not an official curriculum publication.
Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.