Track quiz
Eight lessons, one rule each. Keep the table open beside the quiz.
| Idea | The rule |
|---|---|
| A name for steps | A function gives a group of lines one name. Writing the definition runs nothing. It runs at each call, and what gets printed does not change. |
| What you hand it | The name written in the brackets of the definition is the parameter. The value written in the brackets at the call is the argument. |
| The value it hands back | return hands one value back to the line that called it. That line becomes the value. A function that only prints puts a line on the screen. It hands back nothing. |
| One call inside another | A call is a value. So a call can sit inside another line. The inside call runs first. It hands its value up. Only then does the outer line have what it needs. |
| A print in the middle | A print in the middle shows what a box held right then. That is often not what you assumed. Printing changes nothing else about the run. |
| One line at a time | Stepping through shows every box after every line. That is what a print on every line would show. Look first at the row that differs from what the job expects. |
| Predict, then run | Write down what each line should print, before you run it. Predict from the job, not from the program. The first line where they differ is the one to check. |
| Halve the hunt | Say one line is wrong. Its wrong result stays in the total. Check the middle of what is left. Drop the half that cannot hold the fault. Then check again. |
A definition sits alone. No call is anywhere. What runs?
Six repeated lines become one function and two calls. What changes about the output?
In function fare(stops, rider), what is stops?
In fare(3, "adult");, what is 3?
In this language, fare(5) is called, but fare needs two values. What happens?
A function body is one print(8);. What does let due = f(); put in due?
print("Fare: " + ticketFare(3)) works. Why?
In max(total(a), total(b)), what runs first?
A wrong fare prints, and there is no message. What does a print in the middle show?
Does adding a print change the answer of a broken program?
A trace table shows a dash, then 6 on the next row. What was the dash?
You predict by reading the code, then run it. They match. What does that prove?
Ten printed lines are wrong. Which do you check first?
Sixteen lines run in order, and one is wrong. Its wrong result stays in the total. What do you check first?
The fault is on line 10 of 16. Halving takes 4 checks. Checking from the top takes?
Why does halving fail on a jumbled row of cards?
Next comes Data Handling I: Organizing & Visualizing Data. You handed a number to a function here. There you will hand it a whole list.