# Integrated Introductory Programming Practice

Computer Science I · Programming I · https://tryals.app/learn/computer-science-i/integrated-introductory-programming-practice

## Putting It All Together

A real program is not one concept in isolation, but all of them working together. To solve a complete task—like **reading a list of exam scores to report how many passed and the class average**—you must assemble every idea from this unit.

A structured approach keeps complexity manageable:

| Step | Action | Description |
| --- | --- | --- |
| 1 | **Model** | Scores are a **list**; output is a count and average. |
| 2 | **Algorithm** | **Loop** over scores, use a **conditional** for passing. |
| 3 | **Package** | Wrap logic in a **function** like `average(scores)`. |
| 4 | **Guard** | Protect against edge cases like empty lists. |
| 5 | **Test** | Verify typical, empty, and boundary inputs. |

This is the shape of nearly all beginner programming: model data, express logic with loops and conditionals, factor into functions, guard edge cases, and test.

## Formulas and Edge Cases

The fundamental calculation for the class mean is the **average** formula, which divides the sum by the number of elements:

$$\text{average} = \frac{\text{total}}{\text{count}}, \quad \text{count} > 0$$

Here, $\text{total}$ is the sum of all scores, and $\text{count}$ is the number of scores in the list, which **must be greater than zero**.

> **Common pitfall:** Forgetting edge cases when integrating everything. The average of an **empty list** divides by zero, and a score of **exactly 50** sits on the pass/fail boundary (ensure your check uses $\ge 50$, not $> 50$, unless rules state otherwise). 

A program that handles typical inputs but crashes on empty ones is unfinished. Always integrate edge-case checks from the start.

## Practice questions

5 of this lesson's 10 practice questions, with answers. The full set is in the app.

### 1. Select every input that should be in the test suite for the passing-and-average task.

A. A list guaranteed never to be empty and never on the boundary
B. A list where every score passes
C. A list containing a score of exactly 50
D. An empty list
E. A typical mixed list of scores

**Answer:** B. A list where every score passes; C. A list containing a score of exactly 50; D. An empty list; E. A typical mixed list of scores

**Why:** A typical list, an empty list, an all-passing list, and a score of exactly 50 all belong, the last two probe the division-by-zero and boundary edge cases. The option that deliberately avoids both edges tests nothing the typical case does not already cover.

Page: https://tryals.app/practice/computer-science-i/integrated-introductory-programming-practice/select-every-input-that-should-be-in-the-test-suite-for-the

### 2. Order the structured approach to the task: read a list of exam scores and report how many passed and the class average.

**Answer:**

1. Model the data: the scores are a list of numbers
2. Sketch the algorithm in pseudocode, looping over the scores
3. Package the repeated logic in a function such as average(scores)
4. Handle the edge cases, such as an empty list
5. Test with typical, empty, all-passing, and boundary inputs

**Why:** Model the data, sketch the algorithm, package it in a function, guard the edge cases, then test. This is the shape of nearly all beginner programming, the concepts are assembled in this order, not applied one isolated trick at a time.

Page: https://tryals.app/practice/computer-science-i/integrated-introductory-programming-practice/order-the-structured-approach-to-the-task-read-a-list-of-exam-scores

### 3. A program that counts passing scores needs a loop, a conditional and an accumulator, and removing any one of the three breaks it.

**Answer:** True

**Why:** True. The loop visits every score, the conditional decides which count, and the accumulator remembers the running total across iterations. They are the three primitives most simple data processing reduces to, and recognising that shape is what makes an unfamiliar task tractable.

Page: https://tryals.app/practice/computer-science-i/integrated-introductory-programming-practice/a-program-that-counts-passing-scores-needs-a-loop-a-conditional-and

### 4. A beginner writes a working program and cannot explain why it works. Why is that a problem even though the tests pass?

A. Because tests passing is not evidence the program is correct
B. Because it indicates the program was copied from elsewhere
C. Because working code must always be explainable to be committed
D. Because they cannot predict what will break it

**Answer:** D. Because they cannot predict what will break it

**Why:** Working is a snapshot; understanding is what lets you predict behaviour under change. Without it, the first modification or unusual input produces a failure with no model to reason from, which is why tracing by hand and explaining code aloud are skills worth practising deliberately.

Page: https://tryals.app/practice/computer-science-i/integrated-introductory-programming-practice/a-beginner-writes-a-working-program-and-cannot-explain-why-it-works

### 5. Passing is a score of 50 or more. Sort each score by whether it passes or fails.

**Answer:**

- Passes: 50, 51, 100
- Fails: 49, 30, 0

**Why:** Everything at least 50 passes: 50, 51 and 100. Below 50 fails: 49, 30 and 0. The 49-versus-50 pair is the boundary the task warns about, whether the test is >= 50 or > 50 decides the fate of exactly the score 50.

Page: https://tryals.app/practice/computer-science-i/integrated-introductory-programming-practice/passing-is-a-score-of-50-or-more-sort-each-score-by-whether-it
