Ontario Grade 7 Mathematics · Grade 7 Math C3.2
C3.2 · Modify code and explain changes to its output and efficiency
Code is a set of instructions for a computer. A small change to an instruction can change what the computer displays. It can also change how…
Ontario Grade 7 Mathematics
Algebra
Modify a short program and explain its output and efficiency
What you will learn
- Describe what a short piece of code does.
- Modify code to produce a different, intended output.
- Explain how a code change affects the output.
- Compare the efficiency of simple code by counting repeated steps.
Read code by tracing each instruction
repeat 3 times:
count = count + 1
display count
- Read instructions in order.
- Track how each variable changes.
- The output is what the program displays.
Modify code to change its output
- Start with the goal for the program.
- Change an instruction, then trace the changed code.
- Explain the connection between the edit and the new output.
Compare how much work code does
- For these examples, compare repeated actions by counting them.
- More repetitions mean more of that instruction's work.
- A useful change may do more work to produce a needed result.
A reliable way to explain a code change
- State the goal, trace, edit, trace again, and compare.
- Describe output and repeated work separately.
- Use the tested values to support your explanation.
Worked example
Change the number of additions
- Trace the originalThe variable starts at 0. The loop adds 1 four times, so the final value is 4. The program displays 4.
- Make the editChange the loop to repeat 6 times. Each repeat still adds one, so the value increases by six altogether.
- Compare the workThe changed program displays 6. The addition instruction runs 6 times instead of 4, which is two more additions.
Worked example
Change a condition to include 5
- Check the original conditionThe original check is score > 5. A score of 5 is not greater than 5, so it displays “small.” A score of 6 is greater than 5, so it displays “large.”
- Edit the conditionChange the check to score >= 5. The symbol >= means greater than or equal to. The revised condition includes 5 as well as numbers above 5.
- Trace both scoresFor a score of 5, the new condition is true, so the program displays “large.” For a score of 6, it is also true, so the program displays “large.” The program still checks the condition once for each score.
Worked example
Reduce repeated checks
- Count the changed versionThere are 5 entries, and each is checked twice. That makes 10 checks. After the checks, the program displays “checked.”
- Remove the duplicate checkKeep one check for each entry and remove the extra pass through the entries. The program still reaches the display instruction.
- Compare versionsBoth versions display “checked.” The edited version checks 5 entries once, so it makes 5 checks instead of 10. It does fewer repeated actions while keeping the stated output.
Common mistakes and how to avoid them
Lesson summary
- Trace code to work out what it displays.
- Modify an instruction to meet a stated goal, then trace the new version.
- Explain how the edit changes the output.
- Compare simple programs by counting repeated actions.
Check your understanding
Question 1
- 5
- 12
- 14
- 20
Show answer and explanation
Question 2
- The program now treats 8 as meeting the condition.
- The program checks the condition eight times.
- The program always treats values below 8 as meeting the condition.
- The program displays the number 8 no matter what the input is.
Show answer and explanation
Question 3
- 2
- 7
- 9
- 14
Show answer and explanation
Key terms
- Code
- Instructions that tell a computer what to do.
- Trace
- A record of what happens as code instructions run.
- Variable
- A named place in a program for storing a value.
- Output
- Information a program displays or produces.
- Condition
- A check that can be true or false.
- Efficiency
- How much work a program does to reach its result.
Continue through Grade 7 Math
View the complete Grade 7 Math Ontario Grade 7 Mathematics curriculum and lessons
- C3.1 · Write efficient code using counts, subprograms, and control structures
- D1.1 · Explain percent distributions of large populations and samples
- C1.1 · Compare repeating, growing, and shrinking patterns by rate and starting value
- C1.2 · Represent number patterns with tables, expressions, and linear equations
- C1.3 · Extend patterns and use their rules to find missing values
- C2.1 · Add and subtract first-degree monomials using models
Tutor support for C3.2 · Modify code and explain changes to its output and efficiency
Working on C3.2 · Modify code and explain changes to its output and efficiency in Grade 7 Math? Bring the question and your own attempt. In a live session, you can trace a small input step by step, compare expected and actual output, and test an edge case. Ask about the first step that does not make sense, then try a similar question yourself.
Explore math tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.
برای مبحث C3.2 · تغییر کد و توضیح اثر آن بر خروجی و کارایی در درس Grade 7 Math، سؤال و تلاش خود را همراه بیاورید. در جلسه میتوانید یک ورودی کوچک را گامبهگام دنبال کنید، خروجی مورد انتظار و واقعی را مقایسه کنید و یک حالت مرزی را بیازمایید. راهنمای معلم ریاضی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقهای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی میشود.
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 7 Mathematics, expectation C3.2. 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.