{"base":{"id":"cs8-23","subject":"Programming","title":"Combining conditions in code","scene":"pycode","steps":[{"mode":"pyand","eyebrow":"and","title":"Both must be True","body":"Python uses the words and, or, not to combine conditions. With and, both parts must be True. The door opens only with enough points and the key.","controls":[{"id":"score","label":"score","min":0,"max":60,"step":5,"value":20}],"actions":[{"id":"key","label":"Pick up the key"}]},{"mode":"pyor","eyebrow":"or","title":"Either one will do","body":"With or, the result is True if at least one part is True. Each side of or needs its own full comparison: day == \"Sat\" or day == \"Sun\". Change the day.","controls":[{"id":"day","label":"Day of the week (Mon → Sun)","min":0,"max":6,"step":1,"value":2}]},{"mode":"pynot","eyebrow":"not","title":"Flip it","body":"not turns True into False and False into True. Games often keep looping while not game_over. End the game and see what happens.","actions":[{"id":"over","label":"Set game_over = True"}]},{"mode":"testvals","eyebrow":"Testing","title":"Try every combination","body":"To test a combined condition, choose inputs that make each part True and False. Run all four tests for the door.","actions":[{"id":"t0","label":"40 + key"},{"id":"t1","label":"40, no key"},{"id":"t2","label":"10 + key"},{"id":"t3","label":"10, no key"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Spot the bug","body":"A program says: if colour == \"red\" or \"blue\": print(\"Team A\"). It prints Team A for every colour.","question":"How should the condition be written?","options":["colour == \"red\" and \"blue\"","colour == \"red\" or colour == \"blue\"","not colour == \"red\""],"answer":1,"right":"Correct. Each side of or needs a full comparison. A string on its own counts as True.","wrong":"Not quite. Does each side of or compare something?","look":"pyor"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"x == 1 or 2 checks whether x is 1 or 2.\"","body":"Write x == 1 or x == 2. A value on its own, like 2, counts as True, so the first version is always True."},{"tag":"Popular idea","title":"\"One passing test proves the condition works.\"","body":"Each part needs testing as True and as False, plus boundary values."},{"tag":"Popular idea","title":"\"not swaps and into or.\"","body":"not only flips the value of the condition right after it."}]},{"type":"cards","id":"code","eyebrow":"Code","title":"and, or, not in Python","items":[{"tag":"and","title":"Both","body":"if score >= 30 and has_key:\n    print(\"The door opens\")","code":true},{"tag":"or","title":"Either","body":"if day == \"Sat\" or day == \"Sun\":\n    print(\"No school today!\")","code":true},{"tag":"not","title":"Flip","body":"if not game_over:\n    print(\"Keep playing\")","code":true}]},{"type":"cards","id":"games","eyebrow":"In games","title":"Combined conditions in real games","items":[{"tag":"Unlock a level","title":"and","body":"stars >= 3 and coins >= 100"},{"tag":"Game over","title":"or","body":"lives == 0 or time_left <= 0"},{"tag":"Move forward","title":"not","body":"not wall_ahead"}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Truth table test","items":[{"title":"Test your own rule","time":"20 minutes","need":["Paper and a pen","Python if you have it"],"steps":["Invent a game rule with and, e.g. 'level_up if points >= 100 and lives > 0'.","Draw a test table with 4 rows: each part True/False.","Fill in the expected result for each row.","Add two boundary tests (points 99 and 100). If you have Python, run your rule and check."],"why":"Testing every combination and the boundaries is how programmers make sure a combined condition does what they meant.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What does and need to give True?","options":["Both parts True","One part True","Both parts False"],"answer":0,"right":"Correct. and needs both.","wrong":"Not quite. Think of the door."},{"question":"score = 25, has_key = True. Does score >= 30 and has_key give True?","options":["Yes","No","It crashes"],"answer":1,"right":"Correct. score >= 30 is False.","wrong":"Not quite. Check each part."},{"question":"Which gives True when day is \"Sun\"?","options":["day == \"Sat\" and day == \"Sun\"","not day == \"Sun\"","day == \"Sat\" or day == \"Sun\""],"answer":2,"right":"Correct. or needs one part True.","wrong":"Not quite. Which uses or correctly?"},{"question":"game_over = False. What is not game_over?","options":["False","True","None"],"answer":1,"right":"Correct. not flips False to True.","wrong":"Not quite. Flip the value."},{"question":"How many tests cover all True/False combinations of two conditions?","options":["4","2","8"],"answer":0,"right":"Correct. TT, TF, FT, FF.","wrong":"Not quite. Two parts, two values each."},{"question":"Which input is a boundary test for score >= 30?","options":["45","100","30"],"answer":2,"right":"Correct. 30 is exactly on the edge.","wrong":"Not quite. Which value sits on the line?"}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how to write and, or and not in Python","why each side of or needs a full comparison","how to plan tests that make each part True and False","how combined conditions are used in games"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"and","meaning":"True only if both conditions are True."},{"word":"or","meaning":"True if at least one condition is True."},{"word":"not","meaning":"Flips True and False."},{"word":"compound condition","meaning":"Two or more conditions joined with and/or."},{"word":"test case","meaning":"One set of inputs with its expected result."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: Boolean operations"]}]},"overlay":null}