{"base":{"id":"cs10-30","subject":"Programming","title":"Project: a score tracker","scene":"mix","steps":[{"use":"code10","mode":"decomp","eyebrow":"Plan it","title":"Break the problem down","body":"Our project: a program that stores players' names and scores, validates input, finds the winner and the average. First, split it into parts.","actions":[{"id":"split","label":"Split into parts"}]},{"use":"cs10t3","mode":"validate","eyebrow":"Input with validation","title":"Only sensible scores","body":"Scores must be whole numbers from 0 to 100, and names must not be empty. Look at the checks we need.","actions":[{"id":"presence","label":"Name: presence"},{"id":"range","label":"Score: range"},{"id":"type","label":"Score: type"}]},{"use":"py10","mode":"avgmax","eyebrow":"Process","title":"Average and highest","body":"Loop through the arrays to total the scores and find the highest. Step through.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"cs10t3","mode":"bubble","eyebrow":"Sort the leaderboard","title":"Bubble sort the scores","body":"Sort the scores so the leaderboard prints in order. Run the sort.","actions":[{"id":"step","label":"Compare"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"code10","mode":"testdata","eyebrow":"Test it","title":"Try to break it","body":"Test with normal, boundary and abnormal data. Which tests pass?","actions":[{"id":"t0","label":"Test 1"},{"id":"t1","label":"Test 2"},{"id":"t2","label":"Test 3"},{"id":"t3","label":"Test 4"}]},{"use":"cs10t3","mode":"quiz","look":"validate","eyebrow":"Check yourself","title":"Testing","body":"The score tracker accepts scores from 0 to 100.","question":"Which set is the best boundary test data?","options":["50, 60, 70","−1, 0, 100, 101","\"ten\", 3.5"],"answer":1,"right":"Correct. Test just inside and just outside each limit.","wrong":"Not quite. Boundary data sits at the edges of the range."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Python","title":"Input and validation","body":"names, scores = [], []\nfor i in range(4):\n    name = input(\"Name: \").strip()\n    while name == \"\":\n        name = input(\"Name cannot be blank: \").strip()\n    s = input(\"Score 0-100: \")\n    while not s.isdigit() or int(s) > 100:\n        s = input(\"Whole number 0-100: \")\n    names.append(name)\n    scores.append(int(s))","code":true},{"tag":"Python","title":"Process","body":"total = sum(scores)\nbest = 0\nfor i in range(len(scores)):\n    if scores[i] > scores[best]:\n        best = i\nprint(\"Average:\", round(total / len(scores), 1))\nprint(\"Winner:\", names[best])","code":true},{"tag":"Python","title":"Leaderboard sort","body":"n = len(scores)\nfor p in range(n - 1):\n    for i in range(n - 1 - p):\n        if scores[i] < scores[i + 1]:\n            scores[i], scores[i + 1] = scores[i + 1], scores[i]\n            names[i], names[i + 1] = names[i + 1], names[i]","code":true},{"tag":"Test plan","title":"Extract","body":"test  data        expected          actual\n1     72          accepted          accepted ✓\n2     100         accepted          accepted ✓\n3     101         rejected          rejected ✓\n4     \"abc\"       rejected          rejected ✓","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Sorting scores but not names","body":"Swap both arrays together, or the names no longer match."},{"tag":"Mistake","title":"Dividing by zero","body":"If no scores were entered, len(scores) is 0: check first."},{"tag":"Mistake","title":"Validating only once","body":"Use a WHILE loop so bad input is asked again until valid."},{"tag":"Mistake","title":"Testing only at the end","body":"Test each part as you build it."}]},{"type":"cards","id":"method","eyebrow":"Set out your answer","title":"Project stages","items":[{"tag":"1","title":"Analyse","body":"List inputs, processes and outputs."},{"tag":"2","title":"Design","body":"Pseudocode or flowchart for each part."},{"tag":"3","title":"Build","body":"Code one part at a time."},{"tag":"4","title":"Test","body":"Use a test plan with all kinds of data."},{"tag":"5","title":"Evaluate","body":"Does it meet every requirement? What would you improve?"}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Extension","title":"Save to a file","body":"Write the leaderboard to a text file so scores are kept after the program closes: open(\"scores.txt\", \"w\")."},{"tag":"Extension","title":"Menus","body":"Add a menu: 1 add score, 2 show leaderboard, 3 quit. A WHILE loop keeps showing the menu until the user quits."},{"tag":"Real world","title":"Game leaderboards","body":"Online games store millions of scores in databases and use fast sorting and indexing so the top 10 appears instantly."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one on paper before opening the card.","items":[{"tag":"Challenge","title":"Extend","body":"Add a count of how many players scored above the average.\n\nAnswer: count = 0; for s in scores: if s > avg: count += 1","code":true},{"tag":"Challenge","title":"Robust","body":"How would you stop two players having the same name?\n\nAnswer: before appending, check if name in names; if so, ask again."},{"tag":"Challenge","title":"Evaluate","body":"Give one limitation of bubble sort for a leaderboard of 1 million players.\n\nAnswer: it needs about n²/2 comparisons, far too slow; use a faster sort."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Build the score tracker","time":"45 minutes","need":["Python (online or installed)"],"steps":["Write the input-and-validation part and test it.","Add the average and winner.","Add the leaderboard sort.","Write a test plan with at least 6 tests and record the results."],"why":"You completed a full program using arrays, loops, validation, sorting and testing.","safety":"Use made-up names in screenshots."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"The first stage of a project is…","options":["testing","evaluation","analysis"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Which data type stores a score of 72?","options":["Integer","Boolean","String"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Parallel arrays names and scores must be…","options":["sorted separately","kept in the same order","different lengths"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"Which loop repeats until input is valid?","options":["FOR with a fixed count","None","WHILE"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"average = total / count fails when…","options":["count is 0","total is 0","count is 1"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"A test plan records…","options":["only errors","expected and actual results","the code"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"To print a leaderboard highest first, sort…","options":["ascending","randomly","descending"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Evaluation asks…","options":["does the program meet the requirements?","how fast can I type?","what colour is the screen?"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["decompose a problem into input, process and output","validate input with loops","use parallel arrays","calculate totals, averages and maximums","sort records with bubble sort","write and run a test plan","evaluate a program against its requirements"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Decomposition","meaning":"Breaking a problem into smaller parts."},{"word":"Parallel arrays","meaning":"Arrays where the same index refers to the same record."},{"word":"Requirement","meaning":"Something the program must do."},{"word":"Test plan","meaning":"A list of tests with expected and actual results."},{"word":"Evaluation","meaning":"Judging how well a solution meets its requirements."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: tutorial","Raspberry Pi Foundation: Python projects","Raspberry Pi Foundation, Isaac Computer Science: software development","BBC Bitesize, GCSE Computer Science: programming techniques"]}]},"overlay":null}