{"base":{"id":"cs11-03","subject":"Programming","title":"Library routines","scene":"mix","steps":[{"use":"cs11","mode":"lib","eyebrow":"Ready-made routines","title":"ROUND, RANDOM, MOD, DIV","body":"Languages include tested routines you can use straight away. Try each.","controls":[{"id":"v","label":"Value","min":0,"max":10,"step":0.0001,"value":7.4682},{"id":"dp","label":"Decimal places","min":0,"max":3,"step":1,"value":2}],"actions":[{"id":"round","label":"ROUND"},{"id":"random","label":"RANDOM"},{"id":"mod","label":"MOD and DIV"}]},{"use":"pycode","mode":"dice","eyebrow":"Random numbers","title":"Roll the dice","body":"Random numbers make games unpredictable. Roll once, then 100 times.","actions":[{"id":"roll","label":"Roll"},{"id":"roll100","label":"Roll 100"}]},{"use":"py9","mode":"strfns","eyebrow":"String functions","title":"Length and case","body":"LENGTH, UCASE and LCASE are library routines too.","actions":[{"id":"w0","label":"Word 1"},{"id":"w1","label":"Word 2"},{"id":"w2","label":"Word 3"}]},{"use":"pycode","mode":"why","eyebrow":"Why use libraries?","title":"Don't reinvent the wheel","body":"Library code is tested, fast and saves time. Compare writing your own with using a library.","actions":[{"id":"own","label":"Write your own"},{"id":"lib","label":"Use the library"}]},{"use":"cs11","mode":"quiz","look":"lib","eyebrow":"Check yourself","title":"MOD","body":"What is 23 MOD 4?","question":"Choose one.","options":["5","3","5.75"],"answer":1,"right":"Correct: 23 = 5 × 4 + 3.","wrong":"Not quite."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"ROUND","title":"Price","body":"ROUND(12.4567, 2) → 12.46","code":true},{"tag":"RANDOM","title":"Dice in Python","body":"import random\nroll = random.randint(1, 6)","code":true},{"tag":"MOD","title":"Even test","body":"IF n MOD 2 = 0 THEN OUTPUT \"even\"","code":true},{"tag":"DIV","title":"Minutes","body":"mins ← 135 DIV 60   → 2\nsecs ← 135 MOD 60   → 15","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Forgetting to import","body":"In Python, import random before using random.randint."},{"tag":"Mistake","title":"randint includes both ends","body":"randint(1, 6) can return 1 and 6."},{"tag":"Mistake","title":"Confusing MOD and DIV","body":"MOD = remainder; DIV = whole-number quotient."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Science","title":"Pseudo-random","body":"Computers usually generate pseudo-random numbers from a formula and a seed; the same seed gives the same sequence."},{"tag":"Security","title":"True randomness","body":"Encryption keys need unpredictable randomness, often gathered from hardware noise."}]},{"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":"Write","body":"Convert a number of seconds into hours, minutes and seconds using DIV and MOD.\n\nAnswer: h ← s DIV 3600; m ← (s MOD 3600) DIV 60; sec ← s MOD 60.","code":true},{"tag":"Challenge","title":"Predict","body":"What can random.randint(0, 9) * 10 return?\n\nAnswer: 0, 10, 20, … 90."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Number-guessing game","time":"25 minutes","need":["Python"],"steps":["Pick a random number from 1 to 50.","Let the user guess with \"higher\" or \"lower\" hints.","Count the guesses."],"why":"You combine RANDOM, loops and selection.","safety":"None."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"ROUND(3.14159, 2) =","options":["3.1","3.142","3.14"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"17 MOD 3 =","options":["2","5","5.67"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"17 DIV 3 =","options":["2","5","5.67"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"random.randint(1, 3) can return…","options":["only 2","0, 1 or 2","1, 2 or 3"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A library routine is…","options":["pre-written, tested code","a book","a variable"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"n MOD 2 = 1 means n is…","options":["even","odd","zero"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"Which needs import in Python?","options":["print","len","random"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Pseudo-random numbers are…","options":["generated by a formula","truly unpredictable","always the same"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["use ROUND, RANDOM, MOD and DIV","use string library routines","import and use a Python library","explain the benefits of library routines"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Library routine","meaning":"A pre-written subroutine supplied with a language."},{"word":"MOD","meaning":"Remainder after division."},{"word":"DIV","meaning":"Whole-number division."},{"word":"Random number","meaning":"An unpredictable value."},{"word":"Import","meaning":"Load a library into a program."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: random module","Python documentation: built-in functions","Raspberry Pi Foundation, Isaac Computer Science: library routines","BBC Bitesize, GCSE Computer Science: subroutines"]}]},"overlay":null}