{"base":{"id":"cs8-21","subject":"Programming","title":"Decisions in code","scene":"pycode","steps":[{"mode":"pyif","eyebrow":"if and else","title":"A two-way choice in Python","body":"In Python, if checks a condition and else handles everything else. The colon and the indent (4 spaces) show which lines belong to each part. Change the age.","controls":[{"id":"age","label":"Age typed in","min":5,"max":18,"step":1,"value":12}]},{"mode":"pyelif","eyebrow":"elif","title":"More than two choices","body":"elif means ‘else if’. Python checks each condition from the top and runs only the first one that is True. Try each choice, including one the game doesn't expect.","actions":[{"id":"c0","label":"left"},{"id":"c1","label":"right"},{"id":"c2","label":"up"},{"id":"c3","label":"jump"}]},{"mode":"order","eyebrow":"Order matters","title":"Put the strictest test first","body":"Because Python stops at the first True condition, the order can cause a bug. Set the score to 85 and look at the output, then swap the order.","controls":[{"id":"score","label":"Score","min":0,"max":100,"step":1,"value":85}],"actions":[{"id":"fix","label":"Swap the order"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Indent it","body":"Ben writes if lives == 0: on one line, and print(\"Game over\") on the next line, starting right at the left edge. Python shows an error.","question":"What is wrong?","options":["print should be indented","lives should be in quotes","== should be ="],"answer":0,"right":"Correct. Lines inside an if must be indented, usually 4 spaces.","wrong":"Not quite. How does Python know which lines are inside the if?","look":"pyif"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"Indentation is just to make code look neat.\"","body":"In Python, indentation decides which lines belong to if, elif and else. Wrong indents change the program or cause errors."},{"tag":"Popular idea","title":"\"= and == mean the same thing.\"","body":"= stores a value in a variable; == compares two values."},{"tag":"Popular idea","title":"\"Every True condition in an if/elif chain runs.\"","body":"Only the first True one runs; the rest are skipped."}]},{"type":"cards","id":"code","eyebrow":"Code","title":"Python patterns","items":[{"tag":"if / else","title":"Two outcomes","body":"age = int(input(\"Age? \"))\nif age >= 12:\n    print(\"You can play\")\nelse:\n    print(\"Ask an adult\")","code":true},{"tag":"if / elif / else","title":"Several outcomes","body":"if choice == \"left\":\n    print(\"A dark cave\")\nelif choice == \"right\":\n    print(\"A fast river\")\nelse:\n    print(\"You can't go that way\")","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Your own menu","items":[{"title":"Text adventure","time":"25 minutes","need":["A computer with Python (or a free online Python editor)","An adult's permission"],"steps":["Type the left/right/up program from the lesson.","Add a fourth direction with another elif.","Run it and test every direction, plus one it doesn't expect.","Change the messages to make your own story."],"why":"Each elif adds a branch. Testing every branch, and an unexpected input, checks the whole decision.","safety":"Ask an adult before installing anything."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What does elif mean?","options":["else if","end if","every line"],"answer":0,"right":"Correct. It adds another condition.","wrong":"Not quite. Split the word."},{"question":"Which symbol compares two values in Python?","options":["=","==",":"],"answer":1,"right":"Correct. == compares; = assigns.","wrong":"Not quite. Two equals signs."},{"question":"What must end an if line in Python?","options":["A full stop","A colon :","A comma"],"answer":1,"right":"Correct. if age >= 12:","wrong":"Not quite. Look at the end of the if line."},{"question":"choice is \"down\". The code checks left, right, up, then else. What runs?","options":["the left branch","else","nothing"],"answer":1,"right":"Correct. No condition matched.","wrong":"Not quite. Did any condition match?"},{"question":"Why use int(input(...)) for an age?","options":["To make it a string","To print it","To turn the typed text into a number"],"answer":2,"right":"Correct. input gives text; int converts it.","wrong":"Not quite. What type does input give?"},{"question":"if score >= 50 comes before elif score >= 80. Score 90 prints…","options":["the >= 80 message","both","the >= 50 message"],"answer":2,"right":"Correct. The first True condition wins.","wrong":"Not quite. Which check comes first?"}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how to write if and else in Python","why indentation matters","how elif chooses the first True condition","why the order of conditions matters","which inputs test every branch"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"if","meaning":"Runs code only when a condition is True."},{"word":"elif","meaning":"Checks another condition if the earlier ones were False."},{"word":"else","meaning":"Runs when no condition was True."},{"word":"indentation","meaning":"Spaces at the start of a line that show which block it belongs to."},{"word":"==","meaning":"Compares two values for equality."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: if statements"]}]},"overlay":null}