DoAssignment study guide
C3.1 · Write code to analyse data and communicate decisions
Learn to write code to analyse data and communicate decisions through clear examples and targeted practice.
Ontario Grade 8 Mathematics
Algebra
Ontario Grade 8 Mathematics • C3.1
Suppose a class wants to choose an activity using student ratings. The class could record the ratings, use code to summarize them, and explain what the result suggests. In this lesson, data means recorded information. Code means instructions written so a computer can follow them. All example data in this lesson is hypothetical, meaning it is made up for practice. Code can carry out a rule, but people choose the question and the rule, check the result, and explain what it means.
What you will learn
- Plan a question that a set of data can help answer.
- Write simple code instructions to organize and analyse data.
- Check a program’s result and use it to communicate a decision.
Plan the question and the information
Begin by asking a question that the data can help answer. For example: Which activity has the higher average rating? A rating is a score given to an activity. A data set is a group of recorded values considered together.
Before writing code, decide what each value represents and what result will help answer the question. If ratings use a scale from 1 to 5, every value should use that same scale. If you compare two activities, keep their ratings separate. Otherwise, the results will not clearly describe each activity.
A simple plan has three parts: input, process, and output. Input is the information given to the program. Process is what the program does with that information. Output is what the program shows. For this question, the ratings are the input, adding and counting are part of the process, and the averages are possible outputs.
- Start with a question and decide what result could help answer it.
- Record what each value means and keep different groups separate.
- Know what information goes in and what result should come out.
Write clear instructions for the analysis
A list is an ordered group of values stored together. Code can use a list to hold ratings. A loop is an instruction that repeats an action for each value in a list. For example, a loop can add each rating to a total and increase a count by 1 each time.
A total is the sum of the values. A count tells how many values were included. An average, also called the mean, is the total divided by the count. The count matters: dividing by the number of values actually used helps the program work even if the list changes.
A computer follows its instructions. It does not know whether a chosen rule is sensible unless a person decides and explains that rule. For example, a class could use the rule “choose the activity with the higher average rating.” The rule makes the process clear. The result still describes only the data entered.
- Use a list to keep related values together.
- Use a loop to apply the same steps to each value.
- Check that the total and count include every value once.
- State the rule that connects an analysis result to a decision.
Check results and communicate a decision
Testing means trying code with a small set of values whose answer you can check. Work out the expected result by hand, then compare it with the program’s output. If the results differ, check whether the code skipped a value, added one twice, or counted incorrectly.
A clear report gives the decision and the evidence for it. For instance: “Using the rule to choose the higher average, choose Activity A. Its average was higher in these hypothetical ratings.” This tells the reader what was compared and how the choice was made.
Be careful not to say more than the data supports. A result from a small group does not prove what everyone would choose. If two averages are equal, report a tie rather than claiming one is higher. Clear communication includes what the program analysed and what its result means.
- Test code on small data that you can check by hand.
- Use the stated decision rule, including what to do if results tie.
- Report the evidence and avoid claims beyond the data.
A practical code-writing routine
Use a short routine each time you write code to analyse data. First, name the question. Next, identify the data and what each value represents. Then write the steps the program must follow. Finally, test the output and explain the result in a sentence.
Keep instructions precise. “Find the average” is a goal, but the program needs steps: set a total and count to 0, visit each value, add it to the total, increase the count, and divide the total by the count. In a code example, indentation shows which instructions belong inside a loop. Follow the code language’s rules for spelling and punctuation.
The examples below use simple Python-style instructions. They show the important actions rather than every possible feature of a coding language. In each case, the values are hypothetical, and the decision follows only the rule stated in the problem.
- Turn the question into steps a computer can follow.
- Use consistent names so it is clear what each value stores.
- Check both the calculated result and the message that communicates it.
Plan an analysis before coding
| Part | Question to ask | Example |
|---|---|---|
| Input | What information goes in? | Ratings for each activity |
| Process | What steps will code follow? | Add, count, and compare |
| Output | What should the program show? | Averages or the largest count |
| Decision | What rule will guide the choice? | Choose the higher average |
Worked example
Calculate the average rating
A group gives an activity these hypothetical ratings: 4, 3, 5, 4, and 4. Write simple code instructions to calculate the average, then explain the result.
- Store the valuesPut the ratings in one list so the code can visit each one. For example: ratings = [4, 3, 5, 4, 4]. The list contains five values.
- Add and countSet total and count to 0. For each score in ratings, add the score to total and add 1 to count. This includes each rating once.
- Calculate and explainDivide the total by the count. The result is the average for these five hypothetical ratings. It does not mean that every person gave a rating of 4.
Answer: A simple code plan is: ratings = [4, 3, 5, 4, 4]; total = 0; count = 0; for score in ratings: total = total + score; count = count + 1; average = total / count. The average is 4 out of 5.
Check: The five ratings total 20. Dividing by the five ratings gives 4.
Worked example
Compare two activities
Students give two hypothetical activities ratings from 1 to 5. Activity A receives 5, 4, 3, and 4. Activity B receives 4, 4, 4, and 3. Use the rule “choose the higher average” to make a decision.
- Keep the groups separateStore the ratings in separate lists. This lets the program analyse each activity on its own.
- Find the totals and averagesAdd each list and divide by its count. Both lists have four ratings, so both totals are divided by 4.
- Apply the ruleActivity A has the higher average, so the stated rule selects Activity A. A report should mention that the ratings are hypothetical and that the choice follows this rule.
Answer: Choose Activity A under the stated rule. Its average is 4, compared with 3.75 for Activity B. These averages summarize only the hypothetical ratings given.
Check: Each average uses four ratings, and Activity A’s average is greater.
Worked example
Use a count to compare responses
A class records hypothetical votes for three choices: chess receives 6 votes, drawing receives 9 votes, and puzzles receive 5 votes. Write a simple code plan to identify the choice with the most votes and communicate the result.
- Store names and countsKeep each choice paired with its vote count. For example: votes = {"chess": 6, "drawing": 9, "puzzles": 5}. Each name tells what its number counts.
- Compare the countsThe program can check each count and keep track of the largest value seen so far. Here, 6 is less than 9, and 5 is also less than 9. The largest count is 9.
- State the result carefullyA suitable message is: “Drawing received the most votes, with 9, in this hypothetical set.” This communicates the result without claiming that every student voted or that the result predicts another group’s choice.
Answer: The largest vote count is 9, so drawing received the most votes in this hypothetical set. A code plan can compare each stored count and display the name linked to the largest one.
Check: The counts are 6, 9, and 5. The count 9 is greater than both other counts.
Common mistakes and how to avoid them
Dividing a total by the wrong number.
Correction: Count how many values were actually added, then divide by that count.
Mixing values from two different choices.
Correction: Store and analyse each group separately so the results remain clear.
Reporting a decision without explaining the rule.
Correction: State the rule and give the result that supports the choice.
Treating a program’s output as automatically correct.
Correction: Test the code with a small set of values and check the result by hand.
Lesson summary
- Begin with a question that the data can help answer.
- Use clear code steps to store, count, add, or compare values.
- Test the result with a small example you can check.
- State the decision rule and communicate what the output means.
- Keep conclusions limited to the data analysed.
Check your understanding
Question 1
A list contains the values 2, 4, and 6. What average should code calculate?
- 3
- 4
- 6
- 12
Show answer and explanation
4
The values total 12, and there are 3 values. The average is 12 divided by 3, which is 4.
Question 2
Two choices have equal average ratings. The rule is to choose the higher average. What should the program report?
- The first choice has the higher average.
- The second choice has the higher average.
- The averages are tied; neither is higher.
- Combine the averages and call that the winning score.
Show answer and explanation
The averages are tied; neither is higher.
Equal averages mean neither choice has a higher average. The program should report a tie.
Question 3
A program reports that one activity has the higher average in a small set of hypothetical ratings. Which message is best?
- Everyone will prefer this activity.
- The activity has the higher average in these hypothetical ratings.
- The program has proved this activity is always best.
- The result applies to every class.
Show answer and explanation
The activity has the higher average in these hypothetical ratings.
This message reports what the analysed data shows without claiming more than the data supports.
Key terms
- Data
- Recorded information, such as scores or votes.
- Code
- Instructions written so a computer can follow them.
- List
- An ordered group of values stored together.
- Loop
- An instruction that repeats an action for each value in a group.
- Total
- The sum found by adding values together.
- Count
- The number of values included in a group or calculation.
- Average (mean)
- The total of the values divided by how many values there are.
- Input
- Information given to a program.
Continue through Grade 8 Math
View the complete Grade 8 Math Ontario Grade 8 Mathematics curriculum and lessons
- C2.4 · Solve, verify, and graph integer inequalities
- C3.2 · Modify data-analysis code and explain the result
- C1.1 · Compare growing and shrinking patterns by rate and initial value
- C1.2 · Represent rational-number patterns with tables, graphs, and equations
- C1.3 · Extend patterns and predict unknown terms using linear rules
- C1.4 · Create patterns showing relationships among rational numbers
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 8 Mathematics, expectation C3.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.