{"base":{"id":"cs10-22","subject":"Programming","title":"Strings and nested selection","scene":"mix","steps":[{"use":"cs10t3","mode":"strings","eyebrow":"String handling","title":"Length, substring, case","body":"Strings are sequences of characters, each with an index. Move the sliders to take a substring, and try changing case.","controls":[{"id":"start","label":"Start index","min":0,"max":11,"step":1,"value":7},{"id":"len","label":"Length","min":1,"max":6,"step":1,"value":5}],"actions":[{"id":"up","label":"UCASE"},{"id":"low","label":"LCASE"}]},{"use":"py9","mode":"strcmp","eyebrow":"Comparing strings","title":"YES, Yes or yes?","body":"Computers compare strings exactly, so \"Yes\" ≠ \"yes\". Convert to one case before comparing. Try each answer.","actions":[{"id":"a0","label":"Answer 1"},{"id":"a1","label":"Answer 2"},{"id":"a2","label":"Answer 3"},{"id":"run","label":"Run"}]},{"use":"py10","mode":"elif","eyebrow":"Selection with several branches","title":"IF … ELSE IF … ELSE","body":"Only the first true branch runs. Move the mark and step through.","controls":[{"id":"mark","label":"Mark","min":0,"max":100,"step":1,"value":71}],"actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"py10","mode":"ticket","eyebrow":"Nested selection","title":"An IF inside an IF","body":"A ticket machine first checks age, then inside each branch checks another condition. Change the age and run it.","controls":[{"id":"age","label":"Age","min":1,"max":90,"step":1,"value":30}],"actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"cs10t3","mode":"quiz","look":"strings","eyebrow":"Check yourself","title":"Substring","body":"word ← \"COMPUTER\". Indexes start at 0.","question":"What is SUBSTRING(word, 3, 3)?","options":["\"MPU\"","\"PUT\"","\"PUTE\""],"answer":1,"right":"Correct. Start at index 3 (P) and take 3 characters.","wrong":"Not quite. Count C=0, O=1, M=2, P=3."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Pseudocode","title":"Initials","body":"first ← \"Ada\"\nlast ← \"Lovelace\"\ninitials ← SUBSTRING(first,0,1) & SUBSTRING(last,0,1)\nOUTPUT initials      → AL","code":true},{"tag":"Python","title":"Case-insensitive check","body":"answer = input(\"Continue? \").lower()\nif answer == \"yes\":\n    print(\"Continuing\")","code":true},{"tag":"Nested","title":"Cinema ticket","body":"IF age < 12 THEN\n  price ← 5\nELSE\n  IF student = TRUE THEN price ← 7\n  ELSE price ← 10\n  ENDIF\nENDIF","code":true},{"tag":"CASE","title":"Menu choice","body":"CASE OF choice\n  1 : OUTPUT \"Play\"\n  2 : OUTPUT \"Settings\"\n  OTHERWISE OUTPUT \"Invalid\"\nENDCASE","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Off-by-one indexes","body":"Check whether your language counts from 0 or 1."},{"tag":"Mistake","title":"Comparing different cases","body":"Use UCASE or LCASE first so \"Yes\" and \"yes\" match."},{"tag":"Mistake","title":"Wrong order of elif branches","body":"Put the strictest condition first: test ≥ 90 before ≥ 50."},{"tag":"Mistake","title":"Forgetting ENDIF in nested code","body":"Each IF needs its own ENDIF; indent to keep track."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Real world","title":"Unicode","body":"Every character, from A to 你 to 😀, has a Unicode number. Modern strings store these, so programs can handle every language. Python's len(\"😀\") is 1."},{"tag":"Real world","title":"Search boxes","body":"Search engines lower-case your search and trim spaces before matching. That's why \"  CATS \" finds the same pages as \"cats\"."},{"tag":"Going further","title":"Palindromes","body":"A string that reads the same backwards (like \"level\") can be checked with text == text[::-1] in Python."}]},{"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":"Code","body":"Write Python that counts the vowels in a word.\n\nAnswer:\ncount = 0\nfor ch in word.lower():\n    if ch in \"aeiou\":\n        count += 1","code":true},{"tag":"Challenge","title":"Trace","body":"What does SUBSTRING(\"ALGORITHM\", 4, 3) give with 0-based indexes?\n\nAnswer: \"RIT\"."},{"tag":"Challenge","title":"Nested","body":"A game: if score > 100 and lives > 0 output \"Level up\", if score > 100 and lives = 0 output \"Game over: high score\", else \"Keep going\". Write it with nested IFs.\n\nAnswer: IF score > 100 THEN (IF lives > 0 THEN \"Level up\" ELSE \"Game over: high score\") ELSE \"Keep going\"."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Username maker","time":"20 minutes","need":["Python (online or installed) or paper"],"steps":["Ask for first name, last name and birth year.","Make a username from the first 3 letters of each name and the last 2 digits of the year.","Convert it to lower case and print it."],"why":"You practised substrings, concatenation and case conversion.","safety":"Use made-up names if sharing your screen."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"LENGTH(\"Shalo\") =","options":["4","6","5"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"UCASE(\"lab\") =","options":["\"LAB\"","\"Lab\"","\"lab\""],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"With 0-based indexes, the character at index 0 of \"Code\" is…","options":["\"o\"","\"C\"","\"e\""],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"\"Yes\" = \"yes\" is…","options":["TRUE","an error","FALSE"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"In IF…ELSE IF…ELSE, how many branches run?","options":["Exactly one","All true ones","None"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Joining strings is called…","options":["iteration","concatenation","validation"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"In Python, \"data\"[1:3] =","options":["\"ata\"","\"da\"","\"at\""],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A nested IF is…","options":["an IF inside another IF","a loop","a function"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["use LENGTH, SUBSTRING, UCASE and LCASE","compare strings case-insensitively","concatenate strings","write multi-branch selection","write nested IF statements","use CASE statements"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"String","meaning":"A sequence of characters."},{"word":"Index","meaning":"The position of a character."},{"word":"Substring","meaning":"Part of a string."},{"word":"Concatenation","meaning":"Joining strings together."},{"word":"Nested selection","meaning":"An IF inside another IF."},{"word":"CASE","meaning":"A statement that chooses between many values."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: Text Sequence Type — str","Unicode Consortium: What is Unicode?","Raspberry Pi Foundation, Isaac Computer Science: string handling","BBC Bitesize, GCSE Computer Science: selection"]}]},"overlay":null}