Skip to content

CS 101 — Quiz 2 Study Guide

Everything since Exam 1: Days 19 through 32. Exam 1 stopped at procedures, so this is dictionaries onward — plus the two case-study labs and the security material.

Procedures, loops, lists and conditionals are not the subject here, but they are still the machinery. Every dictionary lives inside a loop, and every loop sits inside a handler or a procedure. If for each item in list or to procedure result is still shaky, fix that first, because nothing below will hold without it.

How to use this

Work the practice items before reading the answers at the end. The point is not to recognize the right answer when you see it; it is to produce one from a blank page, which is what you will be asked to do.

This guide is wider than any one quiz. Treat all of it as fair game and do not try to read the weighting off the length of a section — some short sections are things you have to know cold, and some long ones are here because the idea takes a while to explain.

You will have the block reference sheet. You will not have your project, the lab slides, or a phone. Anything you would normally look up by dragging a block out of a drawer and reading its sockets, you need to know by name instead.


1. Dictionaries — Day 19

What you need to be able to do

  • Say what a dictionary is: a collection of key-value pairs. The key is a single thing, usually text or a number. The value can be anything at all — a number, text, a list, another dictionary.
  • Say what makes it different from a list: you reach a list item by its position, and you reach a dictionary value by its key. A dictionary has no position to count to.
  • Know which block does what:
Block What it does The socket people forget
get value for key … in dictionary … or if not found … Looks up one key in one dictionary or if not found — leave it empty and a missing key gives you the text Not found
set value for key … in dictionary … to … Adds the pair if the key is new, replaces the value if the key is already there —
remove entry for key … from dictionary … Deletes the whole pair. Does nothing at all if the key is not there —
get value at key path … or if not found … Walks several levels down in one block The key path is a make a list, and its steps alternate
create empty dictionary A dictionary to fill in later —
make a dictionary A dictionary with pairs written in —
  • Know that keys are case-sensitive. "Quantity" and "quantity" are two different keys, and asking for the wrong one gives you the not-found value with no error and no warning.

Why or if not found matters more than it looks

It is the socket that decides what a failure looks like. If you plug in 0, a broken lookup produces a number that is indistinguishable from real data — "we have zero of those" — and your app keeps running, confidently wrong. While you are building, plug in something you would never mistake for an answer, like "LOOKUP BROKEN", and swap it for 0 once it works.

Leave the socket empty and the block returns the text Not found. Feed that into a + or a < and you get The operation + cannot accept the arguments — which is the single most common error message in this half of the course. If you see it, the first thing to check is a dictionary lookup, not your arithmetic.

Practice

1.1 global scores holds two pairs: ana → 88 and ben → 72. These three blocks run in this order:

get value for key  "cora"  in dictionary (get global scores)  or if not found  0
set value for key  "ben"   in dictionary (get global scores)  to  95
remove entry for key  "dmitri"  from dictionary (get global scores)

What does the first block give back? How many pairs does scores hold at the end, and what is ben's value?

1.2 In one sentence: why can you not use select list item … index 2 on a dictionary?

1.3 A classmate's app shows Not found where a number should be. Name two different things that could be wrong, and say how you would tell them apart.


2. JSON and reading files — Day 20

What you need to be able to do

  • Read a JSON file and say, for any piece of it, whether it is a dictionary or a list. Curly brackets { } are a dictionary. Square brackets [ ] are a list. JSON is these two nested inside each other, to any depth.
  • Know that Web1.JsonTextDecodeWithDictionaries turns JSON text into App Inventor dictionaries and lists. If the file's outermost thing is a { } you get a dictionary; if it is a [ ] you get a list.
  • Write a key path and read one. The rule that makes key paths work:

A key path step has to match the kind of thing it lands on. Landed on a dictionary? The next step is a key (text). Landed on a list? The next step is a position (a number).

Because JSON alternates dictionaries and lists, a real key path usually alternates text, number, text, number. - Remember that App Inventor lists start at 1. If you read positions off the JSON viewer in Firefox, it numbers them starting at 0, and everything you write will be off by one. No error, no red blocks — just a quietly wrong number. - Know the difference between the two lookup blocks. get value for key looks in exactly one dictionary — the one plugged into its socket. It does not search downward. get value at key path is the one that descends.

The event pattern — this is the big one

Reading a file takes real time, so the call does not hand you the answer:

call File1.ReadFrom  fileName  "//inventory.json"      ← starts the work, returns nothing

when File1.GotText  (text)                             ← the answer arrives here, later
do   set global store to  call Web1.JsonTextDecodeWithDictionaries  jsonText (get text)

Any block that uses the file's contents has to go inside File1.GotText. Put it on the line after the call and it runs before the file has been read, which is why the label comes up blank.

You have now seen this shape three times, and it is the same shape every time:

Start the work The answer arrives in
call File1.ReadFrom when File1.GotText
call SpeechRecognizer1.GetText when SpeechRecognizer1.AfterGettingText
call Web1.Get when Web1.GotText

Anything that has to wait — reading, listening, fetching — is built this way.

Multiple screens

Worth knowing even though you mostly meet it in your project:

  • Each screen is independent. A screen cannot see another screen's components or global variables.
  • open another screen with start value passes exactly one item across — so if you need to send several things, send one dictionary or one list holding them.
  • On the new screen, get start value is the block that picks it up.
  • To go back, use close screen. It drops the current screen and reveals the one underneath, which never stopped running. Opening the first screen again instead builds a second copy on top of the first, and doing that repeatedly stacks up screens the back button then has to walk through one at a time.

Practice

2.1 Here is a decoded JSON file sitting in global recipe:

{
  "dish": "pancakes",
  "serves": 4,
  "ingredients": [
    { "item": "flour", "amount": 2,   "unit": "cups" },
    { "item": "milk",  "amount": 1.5, "unit": "cups" },
    { "item": "egg",   "amount": 2,   "unit": "whole" }
  ]
}

Write the key path that gives you the unit of the milk.

2.2 Using the same data, what does each of these give back?

a)  get value for key  "serves"  in dictionary (get global recipe)  or if not found  0
b)  get value for key  "amount"  in dictionary (get global recipe)  or if not found  0
c)  get value at key path  dictionary (get global recipe)
                           key path (make a list  "ingredients"  1  "item")
                           or if not found  0

2.3 A classmate wrote make a list "ingredients" "milk" "amount" and got 0. Explain, in terms of the matching rule above, why that key path cannot work — and say what would have to be true about the file for it to work.

2.4 These four blocks belong in two different event handlers. Sort them, and say which handler each one goes in:

  • call File1.ReadFrom fileName "//recipe.json"
  • set global recipe to call Web1.JsonTextDecodeWithDictionaries jsonText (get text)
  • set TitleLabel.Text to get value for key "dish" in dictionary (get global recipe) or if not found ""
  • set Screen1.Title to "Recipe Box"

3. Saving data — Day 24

What you need to be able to do

  • Know that File1.SaveFile overwrites the file every single time. There is no "append."
  • Understand why that is harmless in a well-built app: you keep the whole collection in a global list, add to that list, and then save the whole list every time. The file that gets overwritten is replaced by a file containing everything, including the new item.
  • Know that an app has to check whether a saved file exists before reading it. On a brand-new install there is no saved file, so the app falls back to the original file that shipped with it.
  • Know that prefixing a filename with / saves it to the app's own storage, and that // in front of a name means a file that was uploaded in the Media area of the Designer.
  • Know that Web1.JsonTextEncode is how an App Inventor list or dictionary becomes JSON text that can be written to a file — the reverse of the decode block.

Practice

3.1 An app lets you add entries to a journal. Each time you tap Save, it adds the new entry to global entries and then saves global entries to /journal.json. You add four entries, close the app, and reopen it. How many entries should the app show, and why does overwriting the file not lose the first three?

3.2 A different app saves correctly — you can see the file written — but every time it reopens, the journal is empty. Name two things you would check.


4. Synthetic speech — Day 26

Not a lot of blocks, but a lot of trap.

  • TextToSpeech and SpeechRecognizer are both non-visible components from the Media drawer. They sit in a row under the Viewer and have no width, height or color — they are capabilities, not things on the screen. (Web and File work the same way.)
  • call TextToSpeech1.Speak message … is a method: it does something and gives nothing back.
  • TextToSpeech1.Pitch and TextToSpeech1.SpeechRate are properties, both on a 0-to-2 scale with 1 as normal. You set them once and they stay set.
  • call SpeechRecognizer1.GetText follows the event pattern from Section 2: it returns nothing, and the words arrive in when SpeechRecognizer1.AfterGettingText with a result parameter.
  • The Slider trap. A Slider's defaults are MinValue 10, MaxValue 50, ThumbPosition 30. If you wire a slider straight to Pitch without changing those in the Designer, every value you send is far above 2, the voice pins at maximum, and the slider appears to do nothing. No error.

Practice

4.1 Why does set Label1.Text to get result have to be inside when SpeechRecognizer1.AfterGettingText rather than under the GetText call?

4.2 A slider wired to SpeechRate makes no audible difference no matter where you drag it. What would you check first, and in which view — Designer or Blocks?


5. No More Pennies — Days 22 and 23

The rule

The Mint struck its last circulating penny in November 2025, and cash change now rounds to the nearest nickel. Only cash rounds; card, check and electronic payments stay exact to the cent.

Change ends in Direction Moves Who it favors
1 round down to 0 −1¢ the store
2 round down to 0 −2¢ the store
3 round up to 5 +2¢ the customer
4 round up to 5 +1¢ the customer
6 round down to 5 −1¢ the store
7 round down to 5 −2¢ the store
8 round up to 10 +2¢ the customer
9 round up to 10 +1¢ the customer
0 or 5 no change 0 exact

A third rule covers tiny purchases: a cash total under 5 cents is charged as 5 cents, unless you pay with exact change.

Watch which number is being rounded. The lab rounds the change — what comes back to the customer — so rounding up gives the customer more and costs the store. The case study on Day 22 describes the same rule applied to the total, where rounding up means the customer pays more. Same rule, opposite beneficiary, so read the question carefully before you decide who came out ahead.

The same rule, written as arithmetic

This is how the lab actually does it, and it is worth being able to go back and forth between the two forms:

to toCents  amount
result  round( get amount × 100 )

to roundCents  cents
result  if    (modulo of (get cents) ÷ 5)  ≥  3
        then  get cents + (5 − modulo of (get cents) ÷ 5)
        else  get cents − (modulo of (get cents) ÷ 5)

Take the change in cents, divide by 5, keep the remainder. A remainder of 1 or 2 rounds down; a remainder of 3 or 4 rounds up; a remainder of 0 is already on a nickel. That is the signage, rewritten.

Two ideas worth more than the arithmetic

Why whole cents first. $10.00 − $7.93 is 2.0700000000000003 in binary floating point, not 2.07. Computers store decimals in binary, and most decimals do not fit exactly, so arithmetic on them lands just beside the number you expected. A remainder test on a number that is a hair off is unreliable. Turn dollars into a whole number of cents first and the remainder test is asking a question about an integer, which is exact. You saw the same thing in TuneMatch when a score came back as 6.652500000000001.

Where the rule lives. calcChange reads no global variables and refuses nobody. Hand it (12.34, 10) and it cheerfully returns −2.35, because it is arithmetic and does not know what a cash drawer is. Checking whether the customer can actually pay is the caller's job. That split is why the same procedure works for the ten-row report and for the Change? text boxes without a single block changing.

The case-study half

  • Four endings round down and four round up, so the rule looks symmetric. It is not symmetric in practice, because prices set at $X.99 plus sales tax push totals toward endings that round up. The skew is in the data, not in the rule.
  • Rounding can never move more than 2¢ on one sale, because the farthest you can be from a nickel is two cents. A hard ceiling on the rate is what makes the break-even argument lopsided.
  • Ten hand-picked transactions prove nothing. The ten in the case study were chosen so the Post Office loses; ten chosen the other way would show the opposite. The national estimate is about 0.023¢ per transaction — roughly twenty times smaller than the hand-picked sample.
  • A policy can be a clear net gain in aggregate and still cost a specific group. People who pay cash cannot opt into exact-cent pricing the way card users can. The aggregate number settles the accounting question, not the fairness one.

Practice

5.1 Fill in the change for each cash transaction:

Total Cash Exact change Change in cents Remainder ÷ 5 Rounded change
$5.49 $10.00
$7.63 $10.00
$4.86 $20.00
$12.22 $20.00

5.2 A customer buys a 3¢ item and pays with three pennies. What is charged, and why does rule 3 not apply?

5.3 Change ≥ 3 to ≥ 4 in roundCents. Which endings now behave differently, and does the net across many transactions move toward the customer or toward the store?

5.4 In two sentences: why does the case study insist that the net cost comes from the distribution of price endings rather than from the rounding rule?


6. Recommenders — Days 27 and 28

The three parts of any AI system

AI  =  data  +  algorithm  +  intelligent output

Change any one of the three and the output changes. Most arguments about recommendation turn out to be arguments about the first column.

Content-based filtering, in three lines

profile    =  the average of each feature across the playlist
distance   =  |dance − dance|  +  |energy − energy|  +  |chill − chill|
recommend  =  the candidate with the smallest distance

Three things to have straight:

  • The profile is an average over the playlist, not over the candidates. Averaging the wrong list gives you a confident wrong answer with no error message.
  • Distance measures disagreement, so lower is better. The recommendation is the smallest number. Expect to get this backwards once.
  • The accumulator has to be reset inside the handler. Setting bestScore to 99999 at initialize global only happens once, when the app starts. Reset it at the top of the click handler and the button works a second time; leave it out and the second tap is wrong in a way the first tap does not reveal.

You also cannot put a loop inside a result socket, which is why featureAverage accumulates into a global and the result block reads that global afterwards. Same shape as the Magic Eight Ball tally.

The scaling lesson — the whole point of the lab

dance, energy and chill all run 0 to 10, so any two tracks differ by at most 10 on each. Tempo is in beats per minute, roughly 40 to 200, so two tracks can differ by nearly 160. Add a raw tempo term to the same sum and one feature out of four now decides the answer by itself:

Candidate three features + raw tempo + tempo ÷ 20
Break My Stride 6.6525 7.1525 6.6775
Before You Go 2.9275 17.4275 3.6525
Riptide — Live at Red Rocks 2.5575 29.0575 3.8825
This Is Me 5.9675 94.4675 10.3925
recommended Riptide Break My Stride Before You Go

Three versions of the same app, the same algorithm, the same data — three different songs. Nothing is broken in any of them. Dividing tempo by 20 turns 40–200 BPM into 2–10, the same range as everything else, which is what putting features on the same scale means.

The general form of this, which is the thing to remember: when you add up differences across features, the feature with the widest range silently wins. Picking the features and their scales is a decision, and it is made by whoever writes the app.

The case-study half

  • Spotify's danceability is a measured number from an analysis engine — "tempo, rhythm stability, beat strength and overall regularity." Nobody voted on it. Its name oversold it: a live recording scores low not because it is undanceable but because a live band does not keep machine time.
  • A roomful of people disagreeing with a number does not make the number an error. It means the number is not measuring what the name implied.
  • The feedback loop. Bauer, Ferraro and Serra studied 330,000 listeners over nine years. About 25% of the artists those listeners chose were women. The recommender did not reproduce 25% — the first six recommended tracks were by men on average, with women appearing around position seven. A system that learns from a skewed history hands back a more skewed future, which then becomes the next history. The fix was to push male artists down a fixed number of positions; in simulation, listening shifted and the recommender eventually ranked women higher on its own.
  • In November 2024 Spotify withdrew developer access to the audio-features and recommendation endpoints. The evidence base for studies like that one is now inside one company.

Practice

6.1 A playlist holds three tracks with these features:

Track dance energy
A 4 2
B 6 5
C 8 8

Work out the playlist profile. Then compute the distance for each candidate and say which one the app recommends:

Candidate dance energy
X 7 4
Y 3 9

6.2 Someone adds a fourth feature, lengthSeconds, which runs from about 120 to 400, and plugs it into the same sum without changing anything else. Predict what happens to the recommendation, and give the one-line fix.

6.3 A classmate's app recommends the last candidate in the list every single time, whatever the data. Name the two most likely causes.

6.4 In two or three sentences: a recommender trained on what people played produces recommendations that are more skewed than the history it learned from. Explain how that happens, and why re-ranking the output is a different kind of intervention from the original ranking.


7. Cybersecurity — Day 30

Vocabulary you should be able to define and tell apart

Term One-line definition
Malware Software written to do harm — steal data, disrupt operations, hold files for ransom
Hacking Gaining unauthorized access to a digital system
Denial of service Preventing access by keeping a system too busy to answer; does not require access
DDoS A denial-of-service attack from many machines at once, usually ones running malware
Data breach Data being exposed or taken, whether or not anything was "broken into"

Note the one that catches people: a denial-of-service attack does not require getting inside anything. That is what makes it different from the other three.

Multi-factor authentication

A factor is a kind of evidence, not a second question. There are three kinds:

Factor Means Examples
Something you know Information in your head Password, PIN, security question, ID number
Something you have A physical object in your possession Phone receiving a code, hardware key, ID card
Something you are A measurement of your body Fingerprint, face, voice

Two factors means two different kinds. A password plus a security question is two things you know — it is a second step, not a second factor, and anyone who learned the first can usually learn the second. A longer password rule is not a second anything.

What is at risk

Data (personal, private, valuable), infrastructure (energy, water, communications, air traffic), financial systems, and the Internet of Things — cameras, cars, security systems, even commercial refrigeration. AI has changed the picture in four ways worth being able to name: agents attacking autonomously, faster discovery of new vulnerabilities, faster exploitation, and a lower skill floor for people who previously could not do this at all.

Practice

7.1 Sort these into know, have and are: a password; a fingerprint; a six-digit code texted to your phone; your mother's maiden name; a USB security key; face unlock; your student ID number.

7.2 Which pairs from 7.1 would make genuine two-factor authentication, and which would only look like it?

7.3 A website is unreachable for six hours, but afterwards no data turns out to have been taken and no account was accessed. Which term from the table fits, and what does that tell you about the attacker's access?


8. Password hashing — Day 32

Why apps do not store passwords

A login screen has exactly one question to answer: is this the right password? Storing the password answers it — and hands every password to anyone who opens the file. So store a fingerprint of the password instead, check the fingerprint, and never check the password. The app never needs the password back. It only needs a yes or a no.

What a hash function has to do

Property What it means Why it matters
Deterministic The same text always gives the same number Otherwise the stored number could never be reproduced and nobody could log in
Spread out One small change gives a completely different number Otherwise similar passwords collide and near-misses let people in
One-way Easy text → number, hard number → text This is what makes it safe to store in the open

Determinism alone is nowhere near enough. set h to 7 and ignore the password entirely is perfectly deterministic, and it logs everyone in.

The lab's hash, and what makes it one-way

to hashText  pw
do     set global h to 7
       for each i from 1 to (length of pw) by 1
       do   set global h to  modulo of ((global h × 31) + (position of i-th char in CHARS)) ÷ 1000000007
result global h
  • The × 31 is what makes position matter. Without it the loop just adds character positions, and addition does not care about order — cat, act and tac would all hash to the same number.
  • The modulo keeps the number from growing forever, and in doing so throws information away on purpose. Once a value has been reduced, which multiple of 1000000007 was removed is simply gone. That is why the function does not run backwards — not because the operation is secret, but because the information no longer exists.
  • Lowercase letters sit at positions 1–26 in CHARS and uppercase at 27–52, so c is 3 and C is
  • That is why one capital letter produces an entirely different hash.

The comparison

The login handler hashes what the user typed and compares number to number. It never compares passwords, because it does not have one to compare against. A missing username has to lose that comparison, which is what the -1 not-found value is for: no hash can ever be -1, because a modulo only produces 0 or more.

Honest limits

  • Collisions exist. Our hash is about 9 digits — roughly a billion possible values — and there are far more than a billion possible passwords, so two different passwords must share a number somewhere. SHA-256 produces 256 bits, around 10⁷⁷ values, which is what makes collisions vanishingly unlikely rather than merely unfound.
  • Identical hashes leak. Two accounts storing the same number chose the same password. Anybody reading the file learns that without cracking anything, and cracking one cracks both.
  • Salt is the fix. A salt is a short random string, different for every user, mixed into the password before hashing. It is stored right next to the hash, in the open — it is not a secret. Its whole job is to make two identical passwords produce two different stored numbers.

Practice

8.1 Hand-trace hashText for the password do, using h starting at 7, h = (h × 31) + position, and positions d = 4, o = 15. (The modulo never fires on numbers this small, so you can ignore it.) Then do Do, where D = 30.

8.2 In one sentence: why does a real website email you a link to set a new password instead of emailing you your old one? What does it tell you about a site that emails your actual password?

8.3 Two accounts in a stored dictionary hold exactly the same number. What has someone learned, and what single change would have prevented it?

8.4 A classmate removes the × 31 from the loop so the body just adds each character's position. The app still runs and gives the same number for the same password every time. Explain what is now wrong with it, with an example.


Blocks to know without looking them up

Dictionaries: create empty dictionary, make a dictionary, get value for key, set value for key, remove entry for key, get value at key path, is key in dictionary?

Files and the web: File.ReadFrom, File.GotText, File.SaveFile, File.Exists, Web.JsonTextDecodeWithDictionaries, Web.JsonTextEncode

Screens: open another screen, open another screen with start value, get start value, close screen

Math you will need in the labs: the ÷ block's modulo option, round, and the block whose dropdown you change to absolute

Media: TextToSpeech.Speak, TextToSpeech.Pitch, TextToSpeech.SpeechRate, SpeechRecognizer.GetText, SpeechRecognizer.AfterGettingText

Still carrying over from before the exam: for each item in list, for each number from … to … by, select list item, length of list, join, to procedure result


Mistakes that cost real points in the labs

Worth reading straight through once the night before. Every one of these came up in class.

  1. The accumulator never gets reset inside the handler. First tap right, every tap after it wrong.
  2. A result block was dragged inside the loop instead of after it, so the answer is whatever the last iteration happened to leave behind.
  3. or if not found left empty, so a missing key returns the text Not found and the next arithmetic block throws the operation cannot accept the arguments.
  4. A key misspelled, or capitalized differently. Keys are case-sensitive and a wrong one fails silently.
  5. Positions counted from 0 because that is what the Firefox JSON viewer shows. App Inventor counts from 1.
  6. < written where > was meant, or the comparison reversed, so the worst match wins.
  7. The code that uses a file's contents written after the call instead of inside the GotText event.
  8. The stacked if used where the inline if / then / else was needed. Only the inline one has a plug on its left edge, so only it fits in a + socket.
  9. Slider defaults left at 10–50 when the property wants 0–2.
  10. open another screen "Screen1" used as a Logout button instead of close screen, stacking up copies of the login screen.

Answers

Section 1

1.1 The first block gives back 0 — cora is not a key, so the not-found value is used. At the end scores still holds two pairs: set value for key on ben replaced his value rather than adding a pair, and removing dmitri did nothing because dmitri was never a key. ben is now 95.

1.2 Because a dictionary has no positions to select — its values are reached by key, and it has no reliable order to count through.

1.3 Either the key is misspelled or wrongly capitalized, or the or if not found socket is empty and the lookup really did fail. Tell them apart by temporarily plugging a distinctive value like "BROKEN" into the socket: if BROKEN appears, the lookup is failing and the key is the problem; if Not found still appears, the socket was the problem.

Section 2

2.1 make a list "ingredients" 2 "unit" — the step into ingredients lands on a list, so the next step is the position 2, which lands on a dictionary, so the last step is the key "unit". It returns "cups".

2.2 (a) 4. (b) 0 — amount is not one of the three top-level keys (dish, serves, ingredients), and get value for key does not search downward. © "flour".

2.3 ingredients is a list, and a list has no keys to match, so the step "milk" cannot land on anything. "milk" is a value sitting under the item key inside one of the dictionaries, not a label on the list. It would work only if the file had been written with the ingredients as a dictionary keyed by name — "ingredients": { "milk": { "amount": 1.5, … } } — which shows how the shape of the file decides the shape of your blocks.

2.4 Screen1.Initialize gets set Screen1.Title and call File1.ReadFrom. File1.GotText gets the decode and then the set TitleLabel.Text, in that order — the label cannot be filled until the decode has produced a dictionary.

Section 3

3.1 Four. Each save overwrote /journal.json, but what it wrote was the whole of global entries, which by then held everything. Overwriting loses nothing as long as you write the complete collection every time.

3.2 Most likely: the app never checks whether the saved file exists and always reads the original file that shipped with it; or it reads the saved file but does so before GotText delivers the contents, so the global is still empty when the list is displayed. A third candidate is a filename mismatch between the save and the read — /journal.json versus //journal.json.

Section 4

4.1 Because GetText returns nothing at all. It starts the listening and hands control back immediately; the words arrive later, as the result parameter of the event. A block placed under the call runs before anybody has finished speaking.

4.2 The Slider's MinValue and MaxValue, in the Designer. The defaults are 10 and 50, so every value the slider sends is far above the 0–2 range SpeechRate accepts, and the rate pins at maximum no matter where the thumb sits.

Section 5

5.1

Total Cash Exact change Cents Remainder Rounded
$5.49 $10.00 $4.51 451 1 → down $4.50
$7.63 $10.00 $2.37 237 2 → down $2.35
$4.86 $20.00 $15.14 1514 4 → up $15.15
$12.22 $20.00 $7.78 778 3 → up $7.80

5.2 It is charged at 3¢ and the change is $0.00. Rule 3 raises a sub-5¢ total to a nickel unless the customer pays with exact change, and three pennies for a 3¢ item is exact change. Without that clause the customer would be charged 5¢ and owe −2¢.

5.3 Remainders of 3 now round down instead of up; remainders of 1, 2 and 4 are unaffected. Fewer transactions round the change up, so less money goes back across the counter and the net moves toward the store. In the lab's ten rows, the three rows with a remainder of 3 each swing by 5¢ in the store's favor — from −2¢ to +3¢ — so the net goes from −3¢ to +12¢. Pushing the test all the way to ≥ 5, as the lab's "break it on purpose" step does, flips the remainder-4 rows as well and lands on +27¢.

5.4 Four endings round down and four round up, so the rule itself is symmetric and would cancel out if the endings came up equally often. They do not: prices set at $X.99 plus sales tax cluster the total on endings of 3, 4, 8 and 9. Any net cost therefore comes from the distribution of the data, not from the rule applied to it — which is why the case study keeps insisting that choosing the sample is the hard part and the arithmetic is the easy part.

Section 6

6.1 Profile: dance (4 + 6 + 8) / 3 = 6, energy (2 + 5 + 8) / 3 = 5. Candidate X: |7 − 6| + |4 − 5| = 1 + 1 = 2. Candidate Y: |3 − 6| + |9 − 5| = 3 + 4 = 7. X is recommended — smallest distance.

6.2 lengthSeconds differences can run to about 280 while the other features differ by at most 10, so the length term swamps the sum and the recommendation becomes "whichever track is closest in duration," regardless of how it sounds. The fix is to scale it before it enters the sum — dividing by about 28 brings 120–400 down to roughly 4–14, close enough to the others to compete fairly.

6.3 Either the comparison is > where it should be <, so every candidate beats the one before it; or bestScore starts at 0 instead of a large number, so the first comparison fails and the last candidate written is the one that sticks. Both produce the same symptom.

6.4 The recommender learns from what was played, and what was played already under-represents some artists. Because its output then shapes what gets played next, the skew feeds back in and compounds, so the recommendations come out more lopsided than the history they were learned from. Re-ranking is different in kind because it is an explicit, visible decision someone made and can be argued about, whereas the original ranking produced the same sort of effect as an unexamined side-effect of the data — the skew was there either way, but only one version has someone's name on it.

Section 7

7.1 Know: password, mother's maiden name, student ID number. Have: the texted code (it proves you hold the phone), the USB security key. Are: fingerprint, face unlock.

7.2 Genuine two-factor: a password plus the texted code, a password plus the USB key, a password plus a fingerprint or face unlock. Only looks like it: a password plus the maiden name, or a password plus the student ID number — both are two things you know, and someone who phished the first can usually find the second.

7.3 A denial-of-service attack (a DDoS if it came from many machines). It tells you the attacker never needed access to the system at all — they made it too busy to answer, which is what separates this from hacking, malware and a data breach.

Section 8

8.1 do: start at 7 → 7 × 31 + 4 = 221 → 221 × 31 + 15 = 6866. Do: start at 7 → 7 × 31 + 30 = 247 → 247 × 31 + 15 = 7672. One capital letter, an entirely different number.

8.2 Because it does not have your old password — not "won't tell you," cannot tell you; all it stored was a hash. A site that emails your actual password is storing passwords in a form it can read, which means anyone who gets the file can read them too.

8.3 That those two accounts chose the same password — learned at a glance, without cracking anything, and cracking either one cracks both. Giving each account its own salt, mixed into the password before hashing, would have made the two stored numbers different.

8.4 Without the × 31 the hash is just 7 plus the sum of the character positions, and addition does not care about order — so every anagram collides. cat, act and tac all hash to the same number, and any one of them would log you in as any other. The function is still deterministic, which is why it looks fine; it just fails the second requirement, spreading values out.