auto / specs /learning_modules.json
rsnarsna
feat(alli-backend): Wave-1 standardization, standalone sys.env node & vault crypto, and DEC-014 security hardening
8628c98
Raw History Blame Contribute Delete
138 kB
[ { "id": "lesson_1_variables", "gate": "Gate A — Fundamentals", "title": "1. Variables & Memory Assignment", "shortDescription": "Learn how programs name, store, and reuse values in memory.", "conceptExplanation": { "overview": "A variable is a named storage container in a computer's memory. Instead of re-typing numbers or text everywhere, you store a value once under a descriptive name (like 'user_age' or 'total_price') and pass it to other nodes.", "keyPoints": [ "In Python, assignment uses '=': variable_name = value.", "Variable names must start with a letter or underscore, not a number.", "Wiring a variable into another node passes its stored value across the wire." ], "whyItMatters": "Without variables, programs could not remember user inputs or calculate dynamic results.", "pythonCode": "# Python Variable Assignment\nuser_age = 25\nprint(f\"Age stored: {user_age}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Create a Variable", "instruction": "Add a Variable node or Constant Number node to the canvas.", "conceptNote": "This allocates a piece of memory for your program.", "pythonStatement": "score = 100" }, { "stepNumber": 2, "title": "Assign a Name and Value", "instruction": "Set the variable identifier to 'score' and value to 100 in the Configuration Drawer.", "conceptNote": "Names should be lowercase with underscores (PEP 8 convention).", "pythonStatement": "# score is now 100" }, { "stepNumber": 3, "title": "Read the Output", "instruction": "Connect the variable output to a Print node and run to verify the output.", "conceptNote": "Data flows out of the right port into downstream nodes.", "pythonStatement": "print(score)" } ], "starterGraph": { "name": "Lesson 1 Starter", "nodes": [ { "id": "score_var", "node_type": "alli.primitive.variable", "position": { "x": 100, "y": 160 }, "data": { "label": "score", "customData": { "var_name": "score", "value": 100, "type_hint": "int" } } }, { "id": "print_node", "node_type": "alli.primitive.print", "position": { "x": 420, "y": 160 }, "data": { "label": "Print Result", "customData": { "prefix": "" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Build a workflow that declares a variable or constant named 'score' with value 100, and connect it to a Print node.", "targetRequirements": { "requiredNodeTypes": [ "variable", "constant", "print" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "result", "expectedValue": 100 } }, "hints": [ "Drag a Number Constant or Variable node onto the canvas.", "Open its inspector to set the value to 100.", "Connect its output port to a Print node's input port." ], "solutionExplanation": "The variable stores 100 in memory and passes it across the wire to the Print node, outputting 100." } }, { "id": "lesson_2_data_types", "gate": "Gate A — Fundamentals", "title": "2. Data Types & Type Conversion", "shortDescription": "Understand Strings vs Integers and learn how to convert between them.", "conceptExplanation": { "overview": "Every value in Python has a data type. '42' (text string) is NOT the same as 42 (integer). If you try to add text to a number, Python raises a TypeError. You must convert ('cast') text to an integer before doing math.", "keyPoints": [ "int: whole numbers like 10, -5, 42.", "float: decimal numbers like 3.14, 99.9.", "str: text wrapped in quotes like 'Hello'.", "bool: True or False decisions." ], "whyItMatters": "Web forms and APIs return data as text strings. Converting them to integers lets you calculate totals and verify conditions.", "pythonCode": "# Type Conversion in Python\nraw_input = \"42\" # str\nnumber = int(raw_input) # converted to int\ntotal = number + 8 # 50" }, "guidedSteps": [ { "stepNumber": 1, "title": "Recognize Text Strings", "instruction": "Notice how text in quotes like '10' is treated as text characters, not a quantity.", "conceptNote": "In Python: '10' + '20' equals '1020' (concatenation), not 30!", "pythonStatement": "text_val = \"42\"" }, { "stepNumber": 2, "title": "Use Type Conversion", "instruction": "Use a Type Conversion node to turn a string into an integer.", "conceptNote": "int('42') parses the string characters into a numeric integer.", "pythonStatement": "parsed = int(\"42\")" }, { "stepNumber": 3, "title": "Perform Arithmetic", "instruction": "Connect the converted integer into an Add node to compute math.", "conceptNote": "Now 42 + 8 correctly calculates 50.", "pythonStatement": "result = parsed + 8" } ], "starterGraph": { "name": "String Concat Quiz Graph", "nodes": [ { "id": "s1", "node_type": "constant.str", "position": { "x": 100, "y": 120 }, "data": { "label": "Str1", "customData": { "var_name": "str_1", "value": "10" } } }, { "id": "s2", "node_type": "constant.str", "position": { "x": 100, "y": 240 }, "data": { "label": "Str2", "customData": { "var_name": "str_2", "value": "20" } } }, { "id": "op", "node_type": "core.binary_op", "position": { "x": 380, "y": 180 }, "data": { "label": "Add", "customData": { "var_name": "concat_res", "operator": "+" } } } ], "edges": [ { "id": "e1", "source": "s1", "target": "op", "target_handle": "a" }, { "id": "e2", "source": "s2", "target": "op", "target_handle": "b" } ] }, "exercise": { "type": "predict_output", "question": "In Python and ALLI, what does \"10\" + \"20\" evaluate to if both values are Strings?", "graph": { "name": "String Concat Quiz", "nodes": [ { "id": "s1", "node_type": "constant.str", "position": { "x": 100, "y": 120 }, "data": { "label": "Str1", "customData": { "var_name": "str_1", "value": "10" } } }, { "id": "s2", "node_type": "constant.str", "position": { "x": 100, "y": 240 }, "data": { "label": "Str2", "customData": { "var_name": "str_2", "value": "20" } } }, { "id": "op", "node_type": "core.binary_op", "position": { "x": 380, "y": 180 }, "data": { "label": "Add", "customData": { "var_name": "concat_res", "operator": "+" } } } ], "edges": [ { "id": "e1", "source": "s1", "target": "op", "target_handle": "a" }, { "id": "e2", "source": "s2", "target": "op", "target_handle": "b" } ] }, "options": [ { "label": "30 (Integer)", "value": "30", "isCorrect": false, "explanation": "Incorrect: String '+' concatenates text without mathematical addition." }, { "label": "\"1020\" (String)", "value": "1020", "isCorrect": true, "explanation": "Correct! When '+' is used on strings, Python joins the characters into '1020'." }, { "label": "TypeError Error", "value": "error", "isCorrect": false, "explanation": "Incorrect: String concatenation is valid in Python." }, { "label": "0 (Undefined)", "value": "0", "isCorrect": false, "explanation": "Incorrect: '10' and '20' are valid string literals." } ] } }, { "id": "lesson_3_arithmetic", "gate": "Gate A — Fundamentals", "title": "3. Arithmetic Operators & Division Safety", "shortDescription": "Calculate sums, products, and handle division-by-zero errors safely.", "conceptExplanation": { "overview": "Arithmetic nodes perform calculations on numbers. Dividing by zero is mathematically impossible and will halt programs with a ZeroDivisionError unless handled properly.", "keyPoints": [ "+: Addition (10 + 20 = 30)", "*: Multiplication (10 * 2 = 20)", "/: True division producing float (10 / 2 = 5.0)", "//: Floor integer division (7 // 2 = 3)", "**: Power / Exponent (2 ** 8 = 256)" ], "whyItMatters": "Every business rule, pricing calculation, and physics simulation relies on arithmetic operators.", "pythonCode": "# Arithmetic in Python\nprice = 100\ndiscount = 20\nfinal_price = price - discount # 80" }, "guidedSteps": [ { "stepNumber": 1, "title": "Connect Numbers to Operators", "instruction": "Feed operand A and operand B into the binary operation node.", "conceptNote": "Both inputs must receive data before the node can execute.", "pythonStatement": "result = a + b" }, { "stepNumber": 2, "title": "Choose the Operator", "instruction": "Select +, -, *, /, or ** in the operator dropdown.", "conceptNote": "Changing operators instantly updates the live preview.", "pythonStatement": "power_result = 2 ** 8 # 256" }, { "stepNumber": 3, "title": "Handle Division by Zero", "instruction": "If input B is 0 with '/' operator, ALLI gives structured recovery advice: change B to non-zero.", "conceptNote": "Zero division cannot produce a real number.", "pythonStatement": "try:\n res = 10 / 0\nexcept ZeroDivisionError:\n print('Cannot divide by zero!')" } ], "starterGraph": { "name": "Broken Div Graph", "nodes": [ { "id": "n_num", "node_type": "constant.int", "position": { "x": 100, "y": 120 }, "data": { "label": "Numerator", "customData": { "var_name": "numerator", "value": 100 } } }, { "id": "n_denom", "node_type": "constant.int", "position": { "x": 100, "y": 240 }, "data": { "label": "Denominator", "customData": { "var_name": "denominator", "value": 0 } } }, { "id": "n_div", "node_type": "core.binary_op", "position": { "x": 380, "y": 180 }, "data": { "label": "Divide", "customData": { "var_name": "div_res", "operator": "/" } } } ], "edges": [ { "id": "e1", "source": "n_num", "target": "n_div", "target_handle": "a" }, { "id": "e2", "source": "n_denom", "target": "n_div", "target_handle": "b" } ] }, "exercise": { "type": "debug_fix", "prompt": "This workflow is failing because it attempts to divide 100 by 0. Fix the denominator node to 5 so the result calculates 20.", "brokenGraph": { "name": "Broken Div Graph", "nodes": [ { "id": "n_num", "node_type": "constant.int", "position": { "x": 100, "y": 120 }, "data": { "label": "Numerator", "customData": { "var_name": "numerator", "value": 100 } } }, { "id": "n_denom", "node_type": "constant.int", "position": { "x": 100, "y": 240 }, "data": { "label": "Denominator", "customData": { "var_name": "denominator", "value": 0 } } }, { "id": "n_div", "node_type": "core.binary_op", "position": { "x": 380, "y": 180 }, "data": { "label": "Divide", "customData": { "var_name": "div_res", "operator": "/" } } } ], "edges": [ { "id": "e1", "source": "n_num", "target": "n_div", "target_handle": "a" }, { "id": "e2", "source": "n_denom", "target": "n_div", "target_handle": "b" } ] }, "bugDescription": "Denominator node currently holds value 0, causing division by zero error (ERR-DIV-ZERO).", "fixCriteria": { "expectedStatus": "success", "expectedTargetOutput": { "nodeId": "n_div", "expectedValue": 20 } }, "hints": [ "Select the 'Denominator' node on canvas.", "Open its configuration drawer.", "Change the value from 0 to 5.", "Click 'Check My Work' or Run Flow to verify." ], "solutionExplanation": "Changing the denominator to 5 allows 100 / 5 = 20 to compute cleanly without zero division." } }, { "id": "lesson_4_comparisons", "gate": "Gate A — Fundamentals", "title": "4. Relational Comparisons", "shortDescription": "Compare values with ==, !=, <, <=, >, >= to produce Boolean decisions.", "conceptExplanation": { "overview": "Relational operators compare two values and return either True or False. For example, comparing if a user's age is greater than or equal to 18 (age >= 18) outputs True for an adult.", "keyPoints": [ "==: Equal to", "!=: Not equal to", ">: Greater than", ">=: Greater than or equal to", "<: Less than", "<=: Less than or equal to" ], "whyItMatters": "Comparisons form the foundation of decision making in programs. Without comparisons, code could not branch.", "pythonCode": "# Relational Comparisons in Python\nage = 20\nis_adult = (age >= 18) # True\nprint(f\"Is adult: {is_adult}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Input Values to Compare", "instruction": "Connect two number nodes into Value A and Value B ports.", "conceptNote": "Comparisons take two operands of compatible types.", "pythonStatement": "is_pass = score >= 50" }, { "stepNumber": 2, "title": "Select Comparison Operator", "instruction": "Select '>=' to check if A reaches or exceeds the threshold B.", "conceptNote": "If A = 30 and B = 25, 30 >= 25 is True.", "pythonStatement": "30 >= 25 # True" } ], "starterGraph": { "name": "Lesson 4 Starter", "nodes": [ { "id": "c1", "node_type": "constant.int", "position": { "x": 100, "y": 120 }, "data": { "label": "ValA", "customData": { "var_name": "val_a", "value": 35 } } }, { "id": "c2", "node_type": "constant.int", "position": { "x": 100, "y": 240 }, "data": { "label": "ValB", "customData": { "var_name": "val_b", "value": 25 } } }, { "id": "cmp", "node_type": "core.compare", "position": { "x": 380, "y": 180 }, "data": { "label": "Compare", "customData": { "var_name": "cmp_res", "operator": ">=" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Build a comparison workflow: Connect a constant with value 35 and a threshold constant with value 25 to a Compare node (>=). Verify it outputs True.", "targetRequirements": { "requiredNodeTypes": [ "constant", "compare" ], "requiredEdgeCount": 2, "expectedTargetOutput": { "portId": "result", "expectedValue": true } }, "hints": [ "Add two Number Constant nodes (35 and 25).", "Add a Compare Values node.", "Set the comparison operator to '>='.", "Connect 35 to port 'a' and 25 to port 'b'." ], "solutionExplanation": "35 is greater than 25, so the Compare node's output port emits Boolean True." } }, { "id": "lesson_5_boolean_logic", "gate": "Gate A — Fundamentals", "title": "5. Boolean Logic (AND, OR, NOT)", "shortDescription": "Combine multiple conditions into compound decisions.", "conceptExplanation": { "overview": "Boolean operators combine true/false values. AND requires both sides to be True. OR requires at least one side to be True. NOT inverts the condition.", "keyPoints": [ "AND: True only if BOTH conditions are True (True and False = False).", "OR: True if EITHER condition is True (False or True = True).", "NOT: Inverts truth value (not True = False)." ], "whyItMatters": "Real-world rules require multiple criteria: e.g. (has_ticket AND is_on_time) or (is_vip).", "pythonCode": "# Boolean Logic in Python\nhas_ticket = True\nis_vip = False\ncan_enter = has_ticket or is_vip # True" }, "guidedSteps": [ { "stepNumber": 1, "title": "Understand AND", "instruction": "AND requires all inputs to be True. If any input is False, the result is False.", "conceptNote": "True and True is True; True and False is False.", "pythonStatement": "valid = (age >= 18) and has_id" }, { "stepNumber": 2, "title": "Understand OR", "instruction": "OR succeeds as long as at least one input is True.", "conceptNote": "False or True is True; False or False is False.", "pythonStatement": "discount = is_student or is_senior" } ], "starterGraph": { "name": "Compound Logic Quiz Graph", "nodes": [ { "id": "b1", "node_type": "constant.bool", "position": { "x": 80, "y": 100 }, "data": { "label": "BoolA", "customData": { "var_name": "b_1", "value": true } } }, { "id": "b2", "node_type": "constant.bool", "position": { "x": 80, "y": 190 }, "data": { "label": "BoolB", "customData": { "var_name": "b_2", "value": false } } }, { "id": "and_op", "node_type": "core.logical_op", "position": { "x": 280, "y": 140 }, "data": { "label": "AndOp", "customData": { "var_name": "and_res", "operator": "and" } } }, { "id": "b3", "node_type": "constant.bool", "position": { "x": 280, "y": 240 }, "data": { "label": "BoolC", "customData": { "var_name": "b_3", "value": true } } }, { "id": "or_op", "node_type": "core.logical_op", "position": { "x": 480, "y": 180 }, "data": { "label": "OrOp", "customData": { "var_name": "or_res", "operator": "or" } } } ], "edges": [ { "id": "e1", "source": "b1", "target": "and_op", "target_handle": "a" }, { "id": "e2", "source": "b2", "target": "and_op", "target_handle": "b" }, { "id": "e3", "source": "and_op", "target": "or_op", "target_handle": "a" }, { "id": "e4", "source": "b3", "target": "or_op", "target_handle": "b" } ] }, "exercise": { "type": "predict_output", "question": "What is the result of: (True AND False) OR True?", "graph": { "name": "Compound Logic Quiz", "nodes": [ { "id": "b1", "node_type": "constant.bool", "position": { "x": 80, "y": 100 }, "data": { "label": "BoolA", "customData": { "var_name": "b_1", "value": true } } }, { "id": "b2", "node_type": "constant.bool", "position": { "x": 80, "y": 190 }, "data": { "label": "BoolB", "customData": { "var_name": "b_2", "value": false } } }, { "id": "and_op", "node_type": "core.logical_op", "position": { "x": 280, "y": 140 }, "data": { "label": "AndOp", "customData": { "var_name": "and_res", "operator": "and" } } }, { "id": "b3", "node_type": "constant.bool", "position": { "x": 280, "y": 240 }, "data": { "label": "BoolC", "customData": { "var_name": "b_3", "value": true } } }, { "id": "or_op", "node_type": "core.logical_op", "position": { "x": 480, "y": 180 }, "data": { "label": "OrOp", "customData": { "var_name": "or_res", "operator": "or" } } } ], "edges": [ { "id": "e1", "source": "b1", "target": "and_op", "target_handle": "a" }, { "id": "e2", "source": "b2", "target": "and_op", "target_handle": "b" }, { "id": "e3", "source": "and_op", "target": "or_op", "target_handle": "a" }, { "id": "e4", "source": "b3", "target": "or_op", "target_handle": "b" } ] }, "options": [ { "label": "True (Boolean)", "value": "true", "isCorrect": true, "explanation": "Correct! True AND False evaluates to False. Then False OR True evaluates to True." }, { "label": "False (Boolean)", "value": "false", "isCorrect": false, "explanation": "Incorrect: The right-hand operand of the OR is True, making the final result True." }, { "label": "None / Null", "value": "null", "isCorrect": false, "explanation": "Incorrect: Boolean expressions always resolve to True or False." } ] } }, { "id": "lesson_6_if_else", "gate": "Gate B — Decisions", "title": "6. Conditional Branching (If / Else)", "shortDescription": "Direct execution down distinct paths and isolate unselected branches.", "conceptExplanation": { "overview": "An If/Else node evaluates an incoming Boolean condition. When the condition is True, only the 'Then' branch runs. When False, only the 'Else' branch runs. The inactive branch is marked 'skipped' and produces zero errors.", "keyPoints": [ "If True: activates Then output port.", "If False: activates Else output port.", "Inactive branches are safely isolated without crashing downstream logic." ], "whyItMatters": "Conditionals give programs intelligence to adapt to different users, errors, and data states.", "pythonCode": "# Conditional Branching in Python\nage = 20\nif age >= 18:\n message = \"Welcome Adult\"\nelse:\n message = \"Welcome Minor\"" }, "guidedSteps": [ { "stepNumber": 1, "title": "Provide Condition", "instruction": "Wire a Boolean comparison or constant into the 'condition' port.", "conceptNote": "The condition decides which pathway executes.", "pythonStatement": "if condition:" }, { "stepNumber": 2, "title": "Wire Then & Else Outputs", "instruction": "Connect the 'then' port to the success action, and 'else' port to the fallback action.", "conceptNote": "Only the selected branch runs; the other is skipped.", "pythonStatement": " do_then_action()\nelse:\n do_else_action()" } ], "starterGraph": { "name": "Lesson 6 Starter", "nodes": [ { "id": "c_cond", "node_type": "constant.bool", "position": { "x": 80, "y": 160 }, "data": { "label": "Condition", "customData": { "var_name": "cond", "value": true } } }, { "id": "branch_node", "node_type": "control.if_else", "position": { "x": 320, "y": 160 }, "data": { "label": "IfElse", "customData": { "var_name": "branch", "condition": true } } }, { "id": "p_then", "node_type": "alli.primitive.print", "position": { "x": 560, "y": 100 }, "data": { "label": "PrintPass", "customData": { "var_name": "print_pass", "value": "Pass", "prefix": "" } } }, { "id": "p_else", "node_type": "alli.primitive.print", "position": { "x": 560, "y": 240 }, "data": { "label": "PrintFail", "customData": { "var_name": "print_fail", "value": "Fail", "prefix": "" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Build an If/Else flow: Connect a Boolean constant (True) to an If/Else node. Wire 'then' to a Print node ('Pass') and 'else' to a Print node ('Fail'). Run to verify 'Pass' executes and 'Fail' is skipped.", "targetRequirements": { "requiredNodeTypes": [ "constant", "if_else", "print" ], "requiredEdgeCount": 3, "expectedTargetOutput": { "portId": "result", "expectedValue": "Pass" } }, "hints": [ "Add a Boolean Constant set to True.", "Add an If / Else Branching node.", "Add two Print nodes: one with 'Pass' and one with 'Fail'.", "Wire True to condition, 'then' to Pass, 'else' to Fail." ], "solutionExplanation": "Because the condition is True, the Then branch executes 'Pass' and the Else branch is cleanly skipped." } }, { "id": "lesson_7_for_loops", "gate": "Gate C — Repetition", "title": "7. For Loops & Bounded Sequences", "shortDescription": "Iterate over a sequence or count of items in a deterministic order.", "conceptExplanation": { "overview": "A For Loop iterates over each item in a collection or range of numbers. Unlike uncontrolled while loops, a for loop is naturally bounded because it visits each element in a sequence exactly once.", "keyPoints": [ "In Python, 'for item in range(count):' runs count times (from 0 to count - 1).", "The iteration variable ('item') holds the value of the current cycle.", "The 'collected' output contains the complete list of elements traversed." ], "whyItMatters": "Iterating over collections of data is foundational to batch processing, aggregations, and data pipelines.", "pythonCode": "# For Loop in Python\ncollected = []\nfor i in range(5):\n collected.append(i)\nprint(collected) # [0, 1, 2, 3, 4]" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add a For Loop", "instruction": "Drag a For Loop node onto the canvas from the Control Flow category.", "conceptNote": "By default, it iterates over range(0, range_count).", "pythonStatement": "for item in range(5):" }, { "stepNumber": 2, "title": "Inspect Parameters", "instruction": "Open the configuration drawer and set Range Count to 5.", "conceptNote": "Range Count sets how many iterations will run.", "pythonStatement": "# range_count = 5" }, { "stepNumber": 3, "title": "Output Collected Items", "instruction": "Connect the 'collected' or 'result' port to a Print node and click Run Flow.", "conceptNote": "The output emits [0, 1, 2, 3, 4] with iteration_count = 5.", "pythonStatement": "print(collected)" } ], "starterGraph": { "name": "Lesson 7 Starter", "nodes": [ { "id": "loop_node", "node_type": "control.for_loop", "position": { "x": 120, "y": 160 }, "data": { "label": "ForLoop", "customData": { "var_name": "for_loop", "iterator_var": "i", "range_count": 5 } } }, { "id": "p_node", "node_type": "alli.primitive.print", "position": { "x": 440, "y": 160 }, "data": { "label": "PrintList", "customData": { "var_name": "print_list", "prefix": "" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Build a For Loop flow: Connect the For Loop node (range_count=5) to the Print node. Run to verify 5 items are generated.", "targetRequirements": { "requiredNodeTypes": [ "for_loop", "print" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "iteration_count", "expectedValue": 5 } }, "hints": [ "Drag a connection wire from the 'collected' or 'result' port of ForLoop to PrintList.", "Ensure the loop node has range_count set to 5." ], "solutionExplanation": "The For Loop node generates 5 integers (0 through 4) and emits the collected list to the print node." } }, { "id": "lesson_8_while_loops", "gate": "Gate C — Repetition", "title": "8. While Loops & State Termination", "shortDescription": "Repeat execution while a condition remains True, bounded by a safety cap.", "conceptExplanation": { "overview": "A While Loop executes repeatedly as long as its continuation condition remains True. In ALLI, all while loops are protected by a strict max_iterations safety cap (default: 100) to ensure accidental infinite loops never freeze the system.", "keyPoints": [ "The continuation condition is re-evaluated before each cycle.", "The state counter must be incremented in each cycle to make progress toward termination.", "The max_iterations safety cap prevents runaway cycles." ], "whyItMatters": "While loops allow algorithms to run until a specific target threshold or convergence condition is satisfied.", "pythonCode": "# Bounded While Loop in Python\ncount = 0\nmax_iter = 100\nwhile count < 5 and count < max_iter:\n count += 1\nprint(count) # 5" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add a While Loop", "instruction": "Add a While Loop node to the canvas.", "conceptNote": "Defaults to starting at 0, stepping by 1, with threshold 5.", "pythonStatement": "while count < 5:" }, { "stepNumber": 2, "title": "Configure Threshold", "instruction": "Set initial_value to 0, step_value to 1, and target_threshold to 5.", "conceptNote": "In each step: count += 1 until count reaches 5.", "pythonStatement": " count += 1" }, { "stepNumber": 3, "title": "Connect and Run", "instruction": "Connect the While Loop output to a Print node and run to verify it reaches 5.", "conceptNote": "The final result is 5 across 5 iterations.", "pythonStatement": "print(count)" } ], "starterGraph": { "name": "Lesson 8 Starter", "nodes": [ { "id": "while_node", "node_type": "control.while_loop", "position": { "x": 120, "y": 160 }, "data": { "label": "WhileLoop", "customData": { "var_name": "while_loop", "initial_value": 0, "step_value": 1, "target_threshold": 5 } } }, { "id": "p_node", "node_type": "alli.primitive.print", "position": { "x": 440, "y": 160 }, "data": { "label": "PrintCount", "customData": { "var_name": "print_count", "prefix": "" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Build a While Loop: Connect the WhileLoop node (initial=0, threshold=5, step=1) to the Print node. Run to verify it terminates with result 5.", "targetRequirements": { "requiredNodeTypes": [ "while_loop", "print" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "result", "expectedValue": 5 } }, "hints": [ "Connect the output of the While Loop to the Print node.", "Check that the threshold is set to 5 and step is 1." ], "solutionExplanation": "The while loop starts at 0 and increments by 1 on each iteration, terminating when count equals 5." } }, { "id": "lesson_9_loop_control", "gate": "Gate C — Repetition", "title": "9. Loop Control (Break & Continue)", "shortDescription": "Prematurely exit a loop or skip iterations using explicit control statements.", "conceptExplanation": { "overview": "The 'break' statement terminates the loop immediately, stopping all further iterations. The 'continue' statement skips the remaining steps of the current iteration and jumps directly to the next cycle.", "keyPoints": [ "'break' immediately exits the loop block.", "'continue' skips only the remainder of the current iteration.", "Both statements require a conditional check (like 'if count == 3: break')." ], "whyItMatters": "Early exits prevent wasted computation when searching for an element or when an error condition occurs.", "pythonCode": "# Loop Control in Python\nfor i in range(10):\n if i == 3:\n break\nprint(i) # 3" }, "guidedSteps": [ { "stepNumber": 1, "title": "Understand Early Exit", "instruction": "When a target value is reached, break exits the loop without visiting remaining items.", "conceptNote": "Stops unnecessary work.", "pythonStatement": "if item == target:\n break" }, { "stepNumber": 2, "title": "Understand Skip (Continue)", "instruction": "When an element should be ignored (e.g. negative numbers), continue skips to the next item.", "conceptNote": "Skips remaining code in current cycle.", "pythonStatement": "if item < 0:\n continue" } ], "starterGraph": { "name": "Break Concept Graph", "nodes": [ { "id": "for_node", "node_type": "control.for_loop", "position": { "x": 100, "y": 150 }, "data": { "label": "ForLoop", "customData": { "var_name": "for_10", "range_count": 10 } } }, { "id": "ctrl_node", "node_type": "control.loop_control", "position": { "x": 350, "y": 150 }, "data": { "label": "LoopControl", "customData": { "var_name": "ctrl", "action": "break" } } } ], "edges": [] }, "exercise": { "type": "predict_output", "question": "If a loop iterates over range(10) [0 through 9] and executes 'if i == 3: break', what is the final value of i?", "graph": { "name": "Break Prediction Graph", "nodes": [ { "id": "loop_10", "node_type": "control.for_loop", "position": { "x": 100, "y": 120 }, "data": { "label": "Loop10", "customData": { "var_name": "loop", "range_count": 10 } } }, { "id": "ctrl_break", "node_type": "control.loop_control", "position": { "x": 350, "y": 120 }, "data": { "label": "BreakAt3", "customData": { "var_name": "brk", "action": "break" } } } ], "edges": [] }, "options": [ { "label": "3", "value": "3", "isCorrect": true, "explanation": "Correct! The loop visits 0, 1, 2, and then upon reaching 3, the break statement terminates the loop immediately." }, { "label": "10", "value": "10", "isCorrect": false, "explanation": "Incorrect: The loop does not run to completion because the break statement terminates it at 3." }, { "label": "9", "value": "9", "isCorrect": false, "explanation": "Incorrect: 9 would be the last index if the loop was uninterrupted, but break stopped it at 3." } ] } }, { "id": "lesson_10_loop_debugging", "gate": "Gate C — Repetition", "title": "10. Loop Debugging & Off-by-One Errors", "shortDescription": "Diagnose and fix off-by-one boundary bugs and infinite loop traps.", "conceptExplanation": { "overview": "The off-by-one error is one of the most common programming bugs. In Python, range(N) produces numbers from 0 to N-1 (N elements in total). Another common bug is forgetting to increment a counter in a while loop, which triggers the safety iteration limit.", "keyPoints": [ "range(5) produces [0, 1, 2, 3, 4] — exactly 5 elements.", "range(4) produces only 4 elements: [0, 1, 2, 3].", "If an exercise requires 5 iterations, range_count must be set to 5." ], "whyItMatters": "Off-by-one errors lead to missing data, incorrect sums, and index-out-of-bounds errors in production systems.", "pythonCode": "# Correcting an Off-by-One Bug\n# Buggy: range(4) has only 4 elements\n# Correct: range(5) has 5 elements (0, 1, 2, 3, 4)\ncorrect_range = range(5)\nprint(len(list(correct_range))) # 5" }, "guidedSteps": [ { "stepNumber": 1, "title": "Identify Missing Item", "instruction": "Notice the broken loop is configured with range_count = 4, producing only 4 items instead of the required 5.", "conceptNote": "Boundary error: missing the 5th item.", "pythonStatement": "# range(4) != range(5)" }, { "stepNumber": 2, "title": "Fix the Range Count", "instruction": "Select the ForLoop node and change Range Count from 4 to 5.", "conceptNote": "Fixes the boundary condition.", "pythonStatement": "for i in range(5):" }, { "stepNumber": 3, "title": "Re-run and Verify", "instruction": "Run the workflow to verify iteration_count equals 5.", "conceptNote": "The fix resolves the bug and produces the target output.", "pythonStatement": "assert len(collected) == 5" } ], "starterGraph": { "name": "Broken Loop Graph", "nodes": [ { "id": "buggy_loop", "node_type": "control.for_loop", "position": { "x": 120, "y": 160 }, "data": { "label": "ForLoop", "customData": { "var_name": "buggy_loop", "range_count": 4 } } }, { "id": "p_node", "node_type": "alli.primitive.print", "position": { "x": 440, "y": 160 }, "data": { "label": "PrintResult", "customData": { "var_name": "print_res", "prefix": "" } } } ], "edges": [ { "id": "e1", "source": "buggy_loop", "target": "p_node", "target_handle": "value" } ] }, "exercise": { "type": "debug_fix", "prompt": "This loop was configured with range_count=4 and only produces 4 iterations instead of the required 5. Fix the range_count parameter on ForLoop to 5 to pass.", "brokenGraph": { "name": "Broken Loop Graph", "nodes": [ { "id": "buggy_loop", "node_type": "control.for_loop", "position": { "x": 120, "y": 160 }, "data": { "label": "ForLoop", "customData": { "var_name": "buggy_loop", "range_count": 4 } } }, { "id": "p_node", "node_type": "alli.primitive.print", "position": { "x": 440, "y": 160 }, "data": { "label": "PrintResult", "customData": { "var_name": "print_res", "prefix": "" } } } ], "edges": [ { "id": "e1", "source": "buggy_loop", "target": "p_node", "target_handle": "value" } ] }, "bugDescription": "ForLoop currently has range_count=4, producing only 4 items instead of 5.", "fixCriteria": { "expectedStatus": "success", "expectedTargetOutput": { "nodeId": "buggy_loop", "portId": "iteration_count", "expectedValue": 5 } }, "hints": [ "Select the ForLoop node on the canvas.", "Change range_count from 4 to 5 in the configuration drawer.", "Run the flow to verify that 5 iterations are executed." ], "solutionExplanation": "Changing range_count to 5 generates 5 iterations (0, 1, 2, 3, 4), satisfying the requirement and fixing the off-by-one error." } }, { "id": "lesson_11_function_defs", "gate": "Gate D — Functions & Scope", "title": "11. Function Definitions: Packaging Reusable Logic", "shortDescription": "Define functions using def, named parameters, and return expressions.", "conceptExplanation": { "overview": "Functions are named blocks of code that perform a specific task. Defining a function packages logic into a reusable unit that can be called whenever needed with different inputs.", "keyPoints": [ "def keyword starts a function definition in Python.", "Parameters act as placeholders for values passed into the function.", "The return statement sends the calculated result back to the caller.", "Docstrings document what the function does and what inputs it expects." ], "whyItMatters": "Without functions, programs would require copying and pasting identical code everywhere, making maintenance difficult and error-prone.", "pythonCode": "def double_it(x):\n \"\"\"Multiply the input by two.\"\"\"\n return x * 2\n\nresult = double_it(21) # 42" }, "guidedSteps": [ { "stepNumber": 1, "title": "Declare Function Name & Parameters", "instruction": "Set the function name to 'double_it' and parameter to 'x'.", "conceptNote": "Function names should be descriptive snake_case identifiers.", "pythonStatement": "def double_it(x):" }, { "stepNumber": 2, "title": "Define the Return Expression", "instruction": "Set the return expression to 'x * 2'.", "conceptNote": "The return expression computes the output value produced when the function runs.", "pythonStatement": " return x * 2" }, { "stepNumber": 3, "title": "Add Documentation", "instruction": "Write a concise docstring explaining what the function returns.", "conceptNote": "Docstrings help other developers understand the function's contract.", "pythonStatement": " \"\"\"Multiply input by two.\"\"\"" } ], "starterGraph": { "name": "Function Def Starter", "nodes": [ { "id": "fn_double", "node_type": "function.def", "position": { "x": 140, "y": 160 }, "data": { "label": "DoubleItDef", "customData": { "func_name": "double_it", "params": "x", "return_expr": "x * 2", "docstring": "Multiply the input by two" } } } ], "edges": [] }, "exercise": { "type": "predict_output", "question": "In Python and ALLI, if double_it(x) is defined with return expression 'x * 2', what does double_it(25) return?", "graph": { "name": "DoubleIt Quiz Graph", "nodes": [ { "id": "fn_def", "node_type": "function.def", "position": { "x": 120, "y": 140 }, "data": { "label": "DoubleDef", "customData": { "func_name": "double_it", "params": "x", "return_expr": "x * 2" } } }, { "id": "call_quiz", "node_type": "function.call", "position": { "x": 420, "y": 140 }, "data": { "label": "DoubleCall", "customData": { "func_name": "double_it", "arg_val": 25 } } } ], "edges": [ { "id": "e1", "source": "fn_def", "target": "call_quiz", "source_handle": "func_ref", "target_handle": "func_in" } ] }, "options": [ { "label": "50", "value": "50", "isCorrect": true, "explanation": "Correct! double_it(25) evaluates 25 * 2 = 50." }, { "label": "25", "value": "25", "isCorrect": false, "explanation": "Incorrect: The function doubles the input." }, { "label": "2525", "value": "2525", "isCorrect": false, "explanation": "Incorrect: The input is a numeric integer, not a string." }, { "label": "None", "value": "None", "isCorrect": false, "explanation": "Incorrect: The function has a return expression." } ] } }, { "id": "lesson_12_function_calls", "gate": "Gate D — Functions & Scope", "title": "12. Function Calls: Passing Arguments & Receiving Results", "shortDescription": "Invoke defined functions by passing arguments and receiving return values.", "conceptExplanation": { "overview": "Calling a function executes its packaged logic with concrete argument values and returns the computed result back into the workflow.", "keyPoints": [ "Arguments provide concrete values to substitute for the function's parameter variables.", "A function call suspends the caller, creates a new local execution frame, and returns a value.", "Return values can be wired to other nodes, printed, or stored in variables." ], "whyItMatters": "Function calls allow complex computations to be abstracted into single intelligible steps.", "pythonCode": "def square(n):\n return n * n\n\narea = square(6) # 36" }, "guidedSteps": [ { "stepNumber": 1, "title": "Connect Function Reference", "instruction": "Wire func_ref from Function Definition to func_in on Function Call.", "conceptNote": "This links the call node to the specific function implementation.", "pythonStatement": "# Function reference wired" }, { "stepNumber": 2, "title": "Pass Arguments", "instruction": "Wire a Constant Integer node into the argument input port.", "conceptNote": "The argument value is passed into parameter 'x'.", "pythonStatement": "result = double_it(21)" }, { "stepNumber": 3, "title": "Inspect the Result", "instruction": "Run the workflow and check the Function Call output port 'result'.", "conceptNote": "The calculated return value (42) is now available for downstream nodes.", "pythonStatement": "print(result) # 42" } ], "starterGraph": { "name": "Function Call Starter", "nodes": [ { "id": "fn_node", "node_type": "function.def", "position": { "x": 100, "y": 120 }, "data": { "label": "DoubleDef", "customData": { "func_name": "double_it", "params": "x", "return_expr": "x * 2" } } }, { "id": "arg_node", "node_type": "constant.int", "position": { "x": 100, "y": 260 }, "data": { "label": "Arg21", "customData": { "var_name": "arg_val", "value": 21 } } }, { "id": "call_node", "node_type": "function.call", "position": { "x": 380, "y": 180 }, "data": { "label": "DoubleCall", "customData": { "func_name": "double_it" } } } ], "edges": [ { "id": "e1", "source": "fn_node", "target": "call_node", "source_handle": "func_ref", "target_handle": "func_in" }, { "id": "e2", "source": "arg_node", "target": "call_node", "target_handle": "arg" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct a workflow with a Function Definition for 'double_it' (x * 2), a Constant Integer 21, and a Function Call node. Connect the constant into the Function Call so it produces 42.", "targetRequirements": { "requiredNodeTypes": [ "function.def", "constant.int", "function.call" ], "requiredEdgeCount": 2, "expectedTargetOutput": { "portId": "result", "expectedValue": 42 } }, "hints": [ "Add a Function Definition node and set func_name to 'double_it' and return_expr to 'x * 2'.", "Add a Constant Integer node and set its value to 21.", "Add a Function Call node and wire the constant into its argument input.", "Run the flow to verify that result equals 42." ], "solutionExplanation": "The Function Definition specifies double_it(x) = x * 2. Passing 21 into the call node evaluates 21 * 2 = 42." } }, { "id": "lesson_13_variable_scope", "gate": "Gate D — Functions & Scope", "title": "13. Variable Scope: Local Isolation & Scope Boundaries", "shortDescription": "Understand local variables inside functions vs global variables on the canvas.", "conceptExplanation": { "overview": "Variables defined inside a function belong to its local scope. They cannot be seen outside the function, and modifying them does not change global variables with the same name.", "keyPoints": [ "Local Scope: variables created inside a function exist only during the function's execution.", "Global Scope: variables defined at the top level of the canvas or module.", "Name Shadowing: a local parameter 'x' shadows global 'x' inside the function without modifying the global 'x'.", "Encapsulation prevents accidental side-effects and bugs in large programs." ], "whyItMatters": "Scope isolation ensures functions are safe to use anywhere without worrying that internal variable names will corrupt the rest of your program.", "pythonCode": "x = 100 # Global variable\n\ndef modify(x):\n x = 999 # Local parameter\n return x\n\nprint(modify(50)) # 999\nprint(x) # Still 100!" }, "guidedSteps": [ { "stepNumber": 1, "title": "Inspect Global Variable", "instruction": "Create a global variable 'x' set to 100.", "conceptNote": "Global variables are accessible throughout the main workflow.", "pythonStatement": "x = 100 # Global scope" }, { "stepNumber": 2, "title": "Execute Local Function", "instruction": "Call a function that accepts parameter 'x' and computes 'x * 2'.", "conceptNote": "Inside the function, 'x' refers to the local argument, not the global variable.", "pythonStatement": "result = modify(50) # Local x = 50" }, { "stepNumber": 3, "title": "Verify Scope Isolation", "instruction": "Check the global variable 'x' to confirm it remains 100.", "conceptNote": "Local execution frames protect global state from unintended mutation.", "pythonStatement": "assert x == 100 # Scope preserved" } ], "starterGraph": { "name": "Scope Isolation Starter", "nodes": [ { "id": "glob_x", "node_type": "alli.primitive.variable", "position": { "x": 100, "y": 120 }, "data": { "label": "GlobalVarX", "customData": { "var_name": "x", "value": 100 } } }, { "id": "fn_scope", "node_type": "function.def", "position": { "x": 100, "y": 260 }, "data": { "label": "ModifyDef", "customData": { "func_name": "modify", "params": "x", "return_expr": "x * 2" } } }, { "id": "call_scope", "node_type": "function.call", "position": { "x": 380, "y": 260 }, "data": { "label": "ModifyCall", "customData": { "func_name": "modify", "arg_val": 50 } } }, { "id": "scope_insp", "node_type": "core.scope", "position": { "x": 380, "y": 120 }, "data": { "label": "ScopeInspector", "customData": { "var_name": "x", "scope_type": "global" } } } ], "edges": [ { "id": "e1", "source": "fn_scope", "target": "call_scope", "source_handle": "func_ref", "target_handle": "func_in" } ] }, "exercise": { "type": "predict_output", "question": "A global variable 'x' is set to 100. A function 'modify(x)' runs with argument 50 and returns 100. What is the value of the global variable 'x' after the function executes?", "graph": { "name": "Scope Quiz Graph", "nodes": [ { "id": "glob_x", "node_type": "alli.primitive.variable", "position": { "x": 100, "y": 120 }, "data": { "label": "GlobalVarX", "customData": { "var_name": "x", "value": 100 } } }, { "id": "fn_scope", "node_type": "function.def", "position": { "x": 100, "y": 260 }, "data": { "label": "ModifyDef", "customData": { "func_name": "modify", "params": "x", "return_expr": "x * 2" } } } ], "edges": [] }, "options": [ { "label": "100 (Unchanged)", "value": "100", "isCorrect": true, "explanation": "Correct! Function parameters are local to the function frame and never mutate global variables." }, { "label": "50", "value": "50", "isCorrect": false, "explanation": "Incorrect: 50 was the local argument passed into the function." }, { "label": "0", "value": "0", "isCorrect": false, "explanation": "Incorrect: The global variable retains its assigned value 100." }, { "label": "None", "value": "None", "isCorrect": false, "explanation": "Incorrect: Variable 'x' is initialized to 100." } ] } }, { "id": "lesson_14_reusable_logic", "gate": "Gate D — Functions & Scope", "title": "14. Modular Reusability: Multiple Calls, Clean Pipelines", "shortDescription": "Reuse a single function definition across multiple distinct call nodes (DRY Principle).", "conceptExplanation": { "overview": "The DRY (Don't Repeat Yourself) principle states that every piece of logic must have a single representation in a system. Defining a function once allows it to be invoked with multiple different inputs throughout the pipeline.", "keyPoints": [ "Write Once, Run Many: write a calculation once and reuse it across multiple data points.", "Single Source of Truth: if the formula needs to change, update only the function definition.", "Composability: function outputs can be combined, added, or passed into other functions." ], "whyItMatters": "Reusability is the foundation of clean software architecture. It reduces code bloat, simplifies testing, and prevents copy-paste bugs.", "pythonCode": "def double_it(x):\n return x * 2\n\nval_a = double_it(15) # 30\nval_b = double_it(35) # 70\ntotal = val_a + val_b # 100" }, "guidedSteps": [ { "stepNumber": 1, "title": "Define the Core Logic", "instruction": "Create a single Function Definition node for 'double_it' with return 'x * 2'.", "conceptNote": "This acts as the single source of truth for the doubling formula.", "pythonStatement": "def double_it(x):\n return x * 2" }, { "stepNumber": 2, "title": "Invoke with First Input", "instruction": "Create a Function Call node with argument 15 (evaluates to 30).", "conceptNote": "The first call executes independently in its own frame.", "pythonStatement": "val_a = double_it(15) # 30" }, { "stepNumber": 3, "title": "Invoke with Second Input", "instruction": "Create a second Function Call node with argument 35 (evaluates to 70).", "conceptNote": "Both call nodes reference the same function definition.", "pythonStatement": "val_b = double_it(35) # 70" }, { "stepNumber": 4, "title": "Combine Results", "instruction": "Add the two call outputs together in a Binary Operation node to produce 100.", "conceptNote": "Composing modular function outputs creates elegant, readable workflows.", "pythonStatement": "total = val_a + val_b # 100" } ], "starterGraph": { "name": "Modular Reusability Starter", "nodes": [ { "id": "fn_shared", "node_type": "function.def", "position": { "x": 80, "y": 160 }, "data": { "label": "DoubleItDef", "customData": { "func_name": "double_it", "params": "x", "return_expr": "x * 2" } } }, { "id": "c1", "node_type": "constant.int", "position": { "x": 260, "y": 100 }, "data": { "label": "Num15", "customData": { "value": 15 } } }, { "id": "call_1", "node_type": "function.call", "position": { "x": 440, "y": 100 }, "data": { "label": "Call1", "customData": { "func_name": "double_it" } } }, { "id": "c2", "node_type": "constant.int", "position": { "x": 260, "y": 240 }, "data": { "label": "Num35", "customData": { "value": 35 } } }, { "id": "call_2", "node_type": "function.call", "position": { "x": 440, "y": 240 }, "data": { "label": "Call2", "customData": { "func_name": "double_it" } } }, { "id": "add_totals", "node_type": "core.binary_op", "position": { "x": 680, "y": 170 }, "data": { "label": "SumTotals", "customData": { "operator": "+" } } } ], "edges": [ { "id": "e1", "source": "fn_shared", "target": "call_1", "source_handle": "func_ref", "target_handle": "func_in" }, { "id": "e2", "source": "c1", "target": "call_1", "target_handle": "arg" }, { "id": "e3", "source": "fn_shared", "target": "call_2", "source_handle": "func_ref", "target_handle": "func_in" }, { "id": "e4", "source": "c2", "target": "call_2", "target_handle": "arg" }, { "id": "e5", "source": "call_1", "target": "add_totals", "source_handle": "result", "target_handle": "a" }, { "id": "e6", "source": "call_2", "target": "add_totals", "source_handle": "result", "target_handle": "b" } ] }, "exercise": { "type": "debug_fix", "prompt": "The second function call's input constant is incorrectly set to 10 instead of 35, yielding 50 instead of 100. Fix constant node 'c2' to 35 so double_it(15) + double_it(35) = 100.", "brokenGraph": { "name": "Broken Reusability Graph", "nodes": [ { "id": "fn_shared", "node_type": "function.def", "position": { "x": 80, "y": 160 }, "data": { "label": "DoubleItDef", "customData": { "func_name": "double_it", "params": "x", "return_expr": "x * 2" } } }, { "id": "c1", "node_type": "constant.int", "position": { "x": 260, "y": 100 }, "data": { "label": "Num15", "customData": { "value": 15 } } }, { "id": "call_1", "node_type": "function.call", "position": { "x": 440, "y": 100 }, "data": { "label": "Call1", "customData": { "func_name": "double_it" } } }, { "id": "c2", "node_type": "constant.int", "position": { "x": 260, "y": 240 }, "data": { "label": "NumBuggy", "customData": { "value": 10 } } }, { "id": "call_2", "node_type": "function.call", "position": { "x": 440, "y": 240 }, "data": { "label": "Call2", "customData": { "func_name": "double_it" } } }, { "id": "add_totals", "node_type": "core.binary_op", "position": { "x": 680, "y": 170 }, "data": { "label": "SumTotals", "customData": { "operator": "+" } } } ], "edges": [ { "id": "e1", "source": "fn_shared", "target": "call_1", "source_handle": "func_ref", "target_handle": "func_in" }, { "id": "e2", "source": "c1", "target": "call_1", "target_handle": "arg" }, { "id": "e3", "source": "fn_shared", "target": "call_2", "source_handle": "func_ref", "target_handle": "func_in" }, { "id": "e4", "source": "c2", "target": "call_2", "target_handle": "arg" }, { "id": "e5", "source": "call_1", "target": "add_totals", "source_handle": "result", "target_handle": "a" }, { "id": "e6", "source": "call_2", "target": "add_totals", "source_handle": "result", "target_handle": "b" } ] }, "bugDescription": "Constant node 'c2' has value 10, producing double_it(10) = 20, so total is 30 + 20 = 50 instead of 100.", "fixCriteria": { "expectedStatus": "success", "expectedTargetOutput": { "nodeId": "add_totals", "portId": "result", "expectedValue": 100 } }, "hints": [ "Select constant node 'c2' (NumBuggy) on the canvas.", "Change its value from 10 to 35 in the configuration drawer.", "Run the flow to verify that double_it(15) + double_it(35) = 30 + 70 = 100." ], "solutionExplanation": "Changing c2 to 35 ensures double_it(35) returns 70. Combining 30 + 70 calculates the required sum of 100." } }, { "id": "lesson_15_lists", "gate": "Gate E — Data Structures", "title": "Lists & Dynamic Sequences", "shortDescription": "Create ordered collections, append elements dynamically, and access items using zero-based indexing.", "conceptExplanation": { "overview": "Lists are ordered, mutable sequences of values. In Python, lists are declared with square brackets `[10, 20, 30]`. Elements are indexed starting from 0, and new items can be added dynamically using `.append()`.", "keyPoints": [ "Zero-based indexing: The first item is at index `0`, second at `1`, and negative indices like `-1` access from the end.", "Mutable sequence: Elements can be added with `.append()`, modified in place, or removed.", "Length calculation: The built-in `len(my_list)` function returns the count of items in the list.", "Linear dataflow: Downstream nodes can iterate through a list or pull specific values." ], "whyItMatters": "Lists are the backbone of program data storage, allowing workflows to handle collections of records, batch events, and variable series in a single variable.", "pythonCode": "items = [10, 20, 30]\nitems.append(40)\nfirst = items[0]\ncount = len(items)\nprint(f\"Items: {items}, First: {first}, Total: {count}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Create Initial List", "instruction": "Add a List node ('data.list') and configure 'initial_items' with '[10, 20, 30]'.", "conceptNote": "Lists preserve item order and allow duplicate elements.", "nodeToInspect": "my_list", "pythonStatement": "my_list = [10, 20, 30]" }, { "stepNumber": 2, "title": "Append an Element", "instruction": "Connect a Constant node with value '40' to the 'item' input and set operation to 'append'.", "conceptNote": ".append() increases the list length by 1 and places the new element at the end.", "nodeToInspect": "my_list", "pythonStatement": "my_list.append(40)" }, { "stepNumber": 3, "title": "Inspect Outputs", "instruction": "Run the flow and inspect output ports: 'result' evaluates to '[10, 20, 30, 40]' and 'length' evaluates to 4.", "conceptNote": "Downstream nodes can read the entire collection or access individual elements by index.", "pythonStatement": "print(len(my_list))" } ], "starterGraph": { "name": "List Operations Starter Graph", "nodes": [ { "id": "list_node", "node_type": "data.list", "position": { "x": 100, "y": 150 }, "data": { "label": "NumbersList", "customData": { "operation": "append", "initial_items": "[10, 20, 30]" } } }, { "id": "item_node", "node_type": "constant.int", "position": { "x": 100, "y": 280 }, "data": { "label": "NewItem", "customData": { "value": 40 } } }, { "id": "print_node", "node_type": "io.print", "position": { "x": 380, "y": 200 }, "data": { "label": "PrintList" } } ], "edges": [ { "id": "e1", "source": "item_node", "target": "list_node", "target_handle": "item" }, { "id": "e2", "source": "list_node", "target": "print_node", "source_handle": "result", "target_handle": "value" } ] }, "exercise": { "type": "predict_output", "question": "If a List node starts with '[10, 20, 30]', appends '40', and inspects index 0, what are the values of 'length' and 'item'?", "graph": { "name": "List Predict Graph", "nodes": [ { "id": "l1", "node_type": "data.list", "position": { "x": 100, "y": 100 }, "data": { "label": "TestList", "customData": { "operation": "append", "initial_items": "[10, 20, 30]", "index": 0 } } }, { "id": "c1", "node_type": "constant.int", "position": { "x": 100, "y": 220 }, "data": { "label": "AddVal", "customData": { "value": 40 } } } ], "edges": [ { "id": "e1", "source": "c1", "target": "l1", "target_handle": "item" } ] }, "options": [ { "label": "length = 4, item = 10", "value": "len_4_item_10", "isCorrect": true, "explanation": "Appending 40 expands the list from 3 to 4 elements. The element at 0-based index 0 is 10." }, { "label": "length = 3, item = 20", "value": "len_3_item_20", "isCorrect": false, "explanation": "Appending an element increases the length to 4, not 3." }, { "label": "length = 4, item = 40", "value": "len_4_item_40", "isCorrect": false, "explanation": "40 is at index 3 (the end of the list), while index 0 holds 10." }, { "label": "length = 3, item = 10", "value": "len_3_item_10", "isCorrect": false, "explanation": "The list has 4 elements after appending 40." } ] } }, { "id": "lesson_16_dictionaries", "gate": "Gate E — Data Structures", "title": "Dictionaries & Key-Value Mappings", "shortDescription": "Store structured records with unique keys, perform O(1) lookups, and update entries dynamically.", "conceptExplanation": { "overview": "Dictionaries (hash maps) store associative data in key-value pairs: `{'key': 'value'}`. Instead of accessing items by index number, values are queried using expressive identifiers, offering lightning-fast O(1) lookup times.", "keyPoints": [ "Keys must be unique and hashable (strings, numbers, tuples).", "Lookup with `.get(key, default)` returns the value safely without raising KeyError if the key is missing.", "Dynamic updates: assigning `dict[key] = value` modifies an existing entry or creates a new one.", "Inspection: `.keys()` extracts all dictionary keys; `.values()` extracts all associated data." ], "whyItMatters": "Most software interfaces, JSON payloads, and user databases represent entities as dictionaries (e.g. user profiles, API responses, configuration files).", "pythonCode": "user = {\"name\": \"Alice\", \"role\": \"Engineer\"}\nuser[\"status\"] = \"Active\"\nrole = user.get(\"role\", \"N/A\")\nprint(f\"Role: {role}, Keys: {list(user.keys())}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Create Dictionary", "instruction": "Add a Dictionary node ('data.dict') with initial dict '{\"name\": \"Alice\", \"role\": \"Engineer\"}'.", "conceptNote": "JSON syntax maps string keys to corresponding attribute values.", "nodeToInspect": "my_dict", "pythonStatement": "user = {\"name\": \"Alice\", \"role\": \"Engineer\"}" }, { "stepNumber": 2, "title": "Query by Key", "instruction": "Set operation to 'get' and query_key to 'role'.", "conceptNote": "Dictionary lookup runs in O(1) average time complexity.", "nodeToInspect": "my_dict", "pythonStatement": "role = user.get(\"role\", \"N/A\")" }, { "stepNumber": 3, "title": "Verify Output", "instruction": "Run the flow and verify output 'val' yields 'Engineer'.", "conceptNote": "Output port 'keys' also emits ['name', 'role'].", "pythonStatement": "print(user[\"role\"])" } ], "starterGraph": { "name": "Dictionary Lookup Starter Graph", "nodes": [ { "id": "dict_node", "node_type": "data.dict", "position": { "x": 120, "y": 150 }, "data": { "label": "UserProfile", "customData": { "operation": "get", "initial_dict": "{\"name\": \"Alice\", \"role\": \"Engineer\"}", "query_key": "role" } } }, { "id": "print_node", "node_type": "io.print", "position": { "x": 400, "y": 150 }, "data": { "label": "PrintRole" } } ], "edges": [ { "id": "e1", "source": "dict_node", "target": "print_node", "source_handle": "val", "target_handle": "value" } ] }, "exercise": { "type": "build_graph", "prompt": "Create a Dictionary node with initial dictionary '{\"status\": \"active\", \"code\": 200}', configure query_key to 'status', and wire output 'val' to an Output / Print node.", "targetRequirements": { "requiredNodeTypes": [ "data.dict", "io.print" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "val", "expectedValue": "active" } }, "hints": [ "Drag a Dictionary node ('data.dict') onto the canvas.", "Set operation to 'get' and query_key to 'status'.", "Wire the Dictionary's 'val' output into an Output / Print node." ], "solutionExplanation": "The Dictionary node queries 'status' from the initial dictionary and outputs 'active' to the Print node." } }, { "id": "lesson_17_tuples", "gate": "Gate E — Data Structures", "title": "Tuples & Sequence Unpacking", "shortDescription": "Protect data against accidental modification with immutable tuples and unpack coordinates simultaneously.", "conceptExplanation": { "overview": "Tuples are ordered collections declared with parentheses `(10, 20)`. Unlike lists, tuples are immutable—once created, elements cannot be modified, added, or removed. Tuples also support simultaneous multi-variable unpacking.", "keyPoints": [ "Immutable: Protects data integrity against unintended side-effects or mutations.", "Unpacking: Simultaneous assignment `(x, y) = point` extracts elements directly into distinct variables.", "Multiple returns: Functions often return multiple values bundled together inside a tuple.", "Memory efficiency: Tuples require less memory overhead than dynamic lists." ], "whyItMatters": "Immutability provides functional safety in distributed pipelines, coordinates, configuration pairs, and multi-value returns.", "pythonCode": "point = (100, 250)\nx, y = point\nprint(f\"X: {x}, Y: {y}, Count: {len(point)}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Define Tuple", "instruction": "Add a Tuple node ('data.tuple') with elements '(100, 250)'.", "conceptNote": "Tuples group related values together into a fixed unit.", "nodeToInspect": "coords", "pythonStatement": "point = (100, 250)" }, { "stepNumber": 2, "title": "Unpack Components", "instruction": "Set operation to 'unpack' to expose individual elements on output ports 'item_1' and 'item_2'.", "conceptNote": "Python tuple unpacking assigns variables simultaneously without temporary holding variables.", "nodeToInspect": "coords", "pythonStatement": "x, y = point" }, { "stepNumber": 3, "title": "Run and Inspect", "instruction": "Run the flow and verify 'item_1' = 100, 'item_2' = 250, and 'length' = 2.", "conceptNote": "Attempting to reassign an element of a tuple in Python throws a TypeError.", "pythonStatement": "print(x, y)" } ], "starterGraph": { "name": "Tuple Unpacking Starter Graph", "nodes": [ { "id": "tuple_node", "node_type": "data.tuple", "position": { "x": 120, "y": 150 }, "data": { "label": "Point2D", "customData": { "operation": "unpack", "elements": "(100, 250)" } } }, { "id": "print_x", "node_type": "io.print", "position": { "x": 380, "y": 100 }, "data": { "label": "PrintX" } }, { "id": "print_y", "node_type": "io.print", "position": { "x": 380, "y": 220 }, "data": { "label": "PrintY" } } ], "edges": [ { "id": "e1", "source": "tuple_node", "target": "print_x", "source_handle": "item_1", "target_handle": "value" }, { "id": "e2", "source": "tuple_node", "target": "print_y", "source_handle": "item_2", "target_handle": "value" } ] }, "exercise": { "type": "predict_output", "question": "A Tuple node packs elements '(100, 250)' and unpacks them. What will output ports 'item_1' and 'item_2' emit?", "graph": { "name": "Tuple Predict Graph", "nodes": [ { "id": "t1", "node_type": "data.tuple", "position": { "x": 100, "y": 100 }, "data": { "label": "CoordTuple", "customData": { "operation": "unpack", "elements": "(100, 250)" } } } ], "edges": [] }, "options": [ { "label": "item_1 = 100, item_2 = 250", "value": "item1_100_item2_250", "isCorrect": true, "explanation": "Tuple unpacking maps the first element (100) to item_1 and the second (250) to item_2." }, { "label": "item_1 = 250, item_2 = 100", "value": "item1_250_item2_100", "isCorrect": false, "explanation": "Tuples preserve strict positional order; 100 is first and 250 is second." }, { "label": "item_1 = [100, 250], item_2 = null", "value": "item1_list_item2_null", "isCorrect": false, "explanation": "Unpacking separates elements into distinct output ports rather than keeping them grouped." }, { "label": "item_1 = (100, 250), item_2 = 2", "value": "item1_tuple_item2_len", "isCorrect": false, "explanation": "item_1 unpacks the first scalar value (100), not the entire tuple." } ] } }, { "id": "lesson_18_sets", "gate": "Gate E — Data Structures", "title": "Sets & Uniqueness Operations", "shortDescription": "Eliminate duplicate data automatically and perform mathematical set union, intersection, and difference.", "conceptExplanation": { "overview": "Sets are unordered collections containing only unique elements: `{1, 2, 3}`. When converting raw data into a set, all duplicate elements are automatically stripped away.", "keyPoints": [ "Uniqueness guarantee: Elements can only appear once in a set.", "Fast membership test: Checking `x in my_set` runs in O(1) constant time.", "Set algebra: Supports mathematical Union (`A | B`), Intersection (`A & B`), and Difference (`A - B`).", "Unordered: Sets do not record insertion index, so items cannot be indexed with `[0]`." ], "whyItMatters": "Data pipelines frequently encounter duplicate user IDs, telemetry records, or tags. Sets guarantee clean unique entity tracking without writing manual deduplication loops.", "pythonCode": "raw_ids = [101, 102, 101, 103, 102]\nunique_ids = set(raw_ids)\nprint(f\"Unique: {unique_ids}, Count: {len(unique_ids)}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Create Deduplicated Set", "instruction": "Add a Set node ('data.set') with initial elements '[101, 102, 101, 103, 102]'.", "conceptNote": "Set initialization automatically discards the repeated 101 and 102 values.", "nodeToInspect": "user_set", "pythonStatement": "unique_ids = set([101, 102, 101, 103, 102])" }, { "stepNumber": 2, "title": "Inspect Set Cardinality", "instruction": "Check output port 'size', which evaluates to 3 unique elements.", "conceptNote": "len(unique_ids) returns the count of unique elements.", "nodeToInspect": "user_set", "pythonStatement": "print(len(unique_ids))" }, { "stepNumber": 3, "title": "Check Membership", "instruction": "Set 'item' parameter to '101' and operation to 'contains' to verify membership output evaluates to True.", "conceptNote": "'in' keyword checks membership in O(1) average time.", "pythonStatement": "101 in unique_ids" } ], "starterGraph": { "name": "Set Deduplication Starter Graph", "nodes": [ { "id": "set_node", "node_type": "data.set", "position": { "x": 120, "y": 150 }, "data": { "label": "UniqueIDs", "customData": { "operation": "create", "initial_set": "[101, 102, 101, 103, 102]" } } }, { "id": "print_node", "node_type": "io.print", "position": { "x": 380, "y": 150 }, "data": { "label": "PrintSize" } } ], "edges": [ { "id": "e1", "source": "set_node", "target": "print_node", "source_handle": "size", "target_handle": "value" } ] }, "exercise": { "type": "debug_fix", "prompt": "A data pipeline expects to deduplicate incoming IDs '[10, 20, 10, 30]', but the Set node operation is currently misconfigured to 'intersection' against an empty set instead of 'create', producing size 0. Fix the Set node's operation to 'create' so output port 'size' evaluates to 3.", "brokenGraph": { "name": "Broken Set Deduplication Graph", "nodes": [ { "id": "dedup_set", "node_type": "data.set", "position": { "x": 120, "y": 150 }, "data": { "label": "DedupSet", "customData": { "operation": "intersection", "initial_set": "[10, 20, 10, 30]" } } }, { "id": "print_node", "node_type": "io.print", "position": { "x": 380, "y": 150 }, "data": { "label": "PrintSize" } } ], "edges": [ { "id": "e1", "source": "dedup_set", "target": "print_node", "source_handle": "size", "target_handle": "value" } ] }, "bugDescription": "The Set node operation is set to 'intersection' without a secondary set, producing an empty set of size 0.", "fixCriteria": { "expectedStatus": "success", "expectedTargetOutput": { "nodeId": "dedup_set", "portId": "size", "expectedValue": 3 } }, "hints": [ "Select the 'dedup_set' node on the canvas.", "In the configuration drawer, change 'operation' from 'intersection' to 'create'.", "Run the flow to verify that [10, 20, 10, 30] deduplicates to {10, 20, 30} with size 3." ], "solutionExplanation": "Configuring the Set node operation to 'create' deduplicates [10, 20, 10, 30] into a unique set of 3 elements." } }, { "id": "lesson_19_try_except", "gate": "Gate F — Modules & OOP", "title": "19. Exception Handling: Try, Except & Resilience", "shortDescription": "Safely catch expected errors like ZeroDivisionError and provide fallback recovery values.", "conceptExplanation": { "overview": "Runtime errors (exceptions) happen during program execution. Instead of letting errors crash the entire workflow, Python uses try...except...finally blocks to intercept specific errors and fall back to safe default values.", "keyPoints": [ "The 'try' block runs protected code that might raise an exception.", "'except ZeroDivisionError' catches division by zero specifically without silencing unrelated errors.", "Fallback values provide graceful degradation so downstream nodes continue executing.", "The 'finally' block executes cleanup tasks regardless of whether an exception occurred." ], "whyItMatters": "Production pipelines handle unpredictable data like zero denominators, missing files, or bad API responses. Exception handling guarantees resilience and zero silent crashes.", "pythonCode": "try:\n result = 100 / 0\nexcept ZeroDivisionError:\n result = 0\nfinally:\n print(\"Cleanup done\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add a Divide Node", "instruction": "Add a Binary Op node ('core.binary_op') dividing 100 by 0 to generate a division-by-zero error.", "conceptNote": "In raw execution, 100 / 0 raises ZeroDivisionError and halts unshielded workflows.", "nodeToInspect": "calc_node", "pythonStatement": "100 / 0 # Raises ZeroDivisionError" }, { "stepNumber": 2, "title": "Connect Try/Except Guard", "instruction": "Wire the divide result into the Try/Except node's 'try_val' port.", "conceptNote": "The Try/Except block catches the upstream ZeroDivisionError.", "nodeToInspect": "try_node", "pythonStatement": "try:\n result = 100 / 0" }, { "stepNumber": 3, "title": "Configure Fallback", "instruction": "Set the Try/Except node's fallback value to 0, catching 'ZeroDivisionError'.", "conceptNote": "The output port 'result' evaluates safely to 0 instead of failing the workflow.", "nodeToInspect": "try_node", "pythonStatement": "except ZeroDivisionError:\n result = 0" } ], "starterGraph": { "name": "Exception Handling Starter Graph", "nodes": [ { "id": "calc_node", "node_type": "core.binary_op", "position": { "x": 100, "y": 150 }, "data": { "label": "DivideByZero", "customData": { "a": 100, "b": 0, "operator": "/" } } }, { "id": "try_node", "node_type": "control.try_except", "position": { "x": 380, "y": 150 }, "data": { "label": "TryGuard", "customData": { "exception_type": "ZeroDivisionError", "fallback": 0 } } } ], "edges": [ { "id": "e1", "source": "calc_node", "target": "try_node", "source_handle": "result", "target_handle": "try_val" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct a resilient calculation workflow. Place a Binary Operation node dividing 100 by 0, and protect it with a Try/Except node configured to catch 'ZeroDivisionError' with fallback 0. Verify output port 'result' recovers with value 0.", "targetRequirements": { "requiredNodeTypes": [ "core.binary_op", "control.try_except" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "result", "expectedValue": 0 } }, "hints": [ "Add a Binary Op node with a=100, b=0, and operator='/'", "Connect its result output to a Try/Except node's 'try_val' port", "Set the Try/Except node fallback parameter to 0 and exception_type to 'ZeroDivisionError'" ], "solutionExplanation": "The Try/Except node intercepts the ZeroDivisionError from the division by zero and outputs the safe fallback value 0." } }, { "id": "lesson_20_modules", "gate": "Gate F — Modules & OOP", "title": "20. Modules & Imports: Standard Libraries & JSON", "shortDescription": "Import approved Python standard library modules like json and parse structured data.", "conceptExplanation": { "overview": "Python's extensive Standard Library offers built-in modules for mathematical calculation (math), JSON serialization (json), and timestamps (datetime). In ALLI, modules are imported from a strict security allowlist.", "keyPoints": [ "'import json' enables json.loads() to deserialize raw JSON strings into Python dictionaries.", "Security boundary: ALLI allows only approved standard modules (json, math, datetime, random) to prevent arbitrary system access.", "Parsed dictionary attributes become immediately accessible to downstream dataflow nodes." ], "whyItMatters": "Modern applications communicate almost entirely via JSON strings. Converting text into structured dictionaries is the baseline requirement of API and web development.", "pythonCode": "import json\n\npayload = '{\"name\": \"Alice\", \"score\": 95}'\ndata = json.loads(payload)\nprint(data[\"score\"]) # 95" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add Module Import Node", "instruction": "Select 'lang.import' with module 'json' and action 'loads'.", "conceptNote": "Imports the standard json library and prepares json.loads() for execution.", "nodeToInspect": "json_import", "pythonStatement": "import json" }, { "stepNumber": 2, "title": "Supply JSON String", "instruction": "Configure default input to '{\"name\": \"Alice\", \"score\": 95}'.", "conceptNote": "json.loads parses this string into a dictionary object.", "nodeToInspect": "json_import", "pythonStatement": "data = json.loads('{\"name\": \"Alice\", \"score\": 95}')" }, { "stepNumber": 3, "title": "Extract Attribute", "instruction": "Wire result into a Dictionary node with operation 'get' and key 'score'.", "conceptNote": "Retrieves value 95 from the parsed dictionary.", "nodeToInspect": "dict_get", "pythonStatement": "score = data.get(\"score\")" } ], "starterGraph": { "name": "JSON Module Starter Graph", "nodes": [ { "id": "json_node", "node_type": "lang.import", "position": { "x": 100, "y": 150 }, "data": { "label": "JSONLoads", "customData": { "module_name": "json", "function_name": "loads", "default_input": "{\"name\": \"Alice\", \"score\": 95}" } } }, { "id": "dict_node", "node_type": "data.dict", "position": { "x": 380, "y": 150 }, "data": { "label": "GetScore", "customData": { "operation": "get", "key": "score" } } } ], "edges": [ { "id": "e1", "source": "json_node", "target": "dict_node", "source_handle": "result", "target_handle": "dict_in" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct a workflow that parses a JSON string into structured data. Use a Module Import node ('lang.import') with module 'json' and function 'loads', and extract the 'score' attribute (value 95) using a Dictionary node.", "targetRequirements": { "requiredNodeTypes": [ "lang.import", "data.dict" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "val", "expectedValue": 95 } }, "hints": [ "Add a Module Import node with module_name='json' and function_name='loads'", "Wire its result to a Dictionary node with operation='get' and key='score'" ], "solutionExplanation": "json.loads converts the JSON string into a Python dict, from which key 'score' returns 95." } }, { "id": "lesson_21_classes", "gate": "Gate F — Modules & OOP", "title": "21. Classes & Instances: Object-Oriented Blueprints", "shortDescription": "Define class blueprints with constructor attributes and instantiate concrete objects.", "conceptExplanation": { "overview": "Object-Oriented Programming (OOP) bundles state (attributes) and behavior (methods) together into a single blueprint called a Class. Creating a concrete object from a class blueprint is called instantiation.", "keyPoints": [ "'class Student:' defines the blueprint and type specification.", "'__init__' constructor initializes instance attributes (self.name, self.score) when an object is created.", "'Student(\"Alice\", 85)' instantiates a distinct object holding its own isolated state.", "In ALLI's DAG engine, instance objects are immutable value containers passed cleanly through typed ports." ], "whyItMatters": "As applications grow, modeling entities like Users, Orders, or Students as cohesive objects keeps data organized and prevents messy dispersed variables.", "pythonCode": "class Student:\n def __init__(self, name, score=0):\n self.name = name\n self.score = score\n\ns1 = Student(\"Alice\", 85)\nprint(s1.name, s1.score)" }, "guidedSteps": [ { "stepNumber": 1, "title": "Define Student Class", "instruction": "Add an 'oop.class_def' node with class name 'Student' and attributes 'name, score'.", "conceptNote": "Declares the Student blueprint with constructor attributes.", "nodeToInspect": "student_class", "pythonStatement": "class Student:\n def __init__(self, name, score):\n self.name = name\n self.score = score" }, { "stepNumber": 2, "title": "Instantiate Object", "instruction": "Add an 'oop.instance' node connected to the class blueprint, passing name 'Alice' and score 85.", "conceptNote": "Creates a new Student object initialized with Alice and 85.", "nodeToInspect": "student_instance", "pythonStatement": "s1 = Student(\"Alice\", 85)" }, { "stepNumber": 3, "title": "Inspect Instance", "instruction": "Run the workflow and check that output object contains { __class__: 'Student', name: 'Alice', score: 85 }.", "conceptNote": "The instance output port stores the student's attributes.", "nodeToInspect": "student_instance", "pythonStatement": "print(s1)" } ], "starterGraph": { "name": "Class and Instance Starter Graph", "nodes": [ { "id": "class_def", "node_type": "oop.class_def", "position": { "x": 100, "y": 150 }, "data": { "label": "StudentClass", "customData": { "class_name": "Student", "attributes": "name, score" } } }, { "id": "create_inst", "node_type": "oop.instance", "position": { "x": 380, "y": 150 }, "data": { "label": "AliceStudent", "customData": { "class_name": "Student", "arg_1_val": "Alice", "arg_2_val": 85 } } } ], "edges": [ { "id": "e1", "source": "class_def", "target": "create_inst", "source_handle": "class_ref", "target_handle": "class_in" } ] }, "exercise": { "type": "build_graph", "prompt": "Create a Student object. Place a Class Definition node ('oop.class_def') with class_name 'Student' and attributes 'name, score'. Connect it to a Create Instance node ('oop.instance') with arg_1='Alice' and arg_2=85. Verify the instance is created with score 85.", "targetRequirements": { "requiredNodeTypes": [ "oop.class_def", "oop.instance" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "val", "expectedValue": { "__class__": "Student", "name": "Alice", "score": 85 } } }, "hints": [ "Connect class_ref from oop.class_def to class_in on oop.instance", "Set arg_1 to 'Alice' and arg_2 to 85" ], "solutionExplanation": "The Class Definition establishes the Student blueprint, and Create Instance invokes __init__ to produce the student instance object." } }, { "id": "lesson_22_methods", "gate": "Gate F — Modules & OOP", "title": "22. Methods & Object State: Invoking Behavior in a DAG", "shortDescription": "Call object methods, pass parameters, mutate object attributes, and return updated state.", "conceptExplanation": { "overview": "Methods are functions bound to an object that have access to its internal state via self. Calling a method can inspect attributes, perform calculations, and update the object's internal data.", "keyPoints": [ "'def add_bonus(self, points):' updates 'self.score += points' and returns the new total.", "DAG consistency: In visual execution, calling a method produces an updated_instance to preserve predictable, acyclic state flow.", "Return values and modified instance states can be chained to downstream methods or output nodes." ], "whyItMatters": "Methods encapsulate business rules directly with the data they modify, ensuring changes happen through tested, controlled pathways.", "pythonCode": "class Student:\n def __init__(self, name, score=85):\n self.name = name\n self.score = score\n def add_bonus(self, points):\n self.score += points\n return self.score\n\ns = Student(\"Alice\", 85)\nnew_score = s.add_bonus(15) # 100" }, "guidedSteps": [ { "stepNumber": 1, "title": "Instantiate Student", "instruction": "Start with a Student instance created with initial score 85.", "conceptNote": "Represents student Alice with score 85.", "nodeToInspect": "student_obj", "pythonStatement": "s = Student(\"Alice\", 85)" }, { "stepNumber": 2, "title": "Call add_bonus Method", "instruction": "Add an 'oop.method_call' node with method_name 'add_bonus' and argument 15.", "conceptNote": "Passes 15 bonus points to the student's score attribute.", "nodeToInspect": "method_call", "pythonStatement": "new_score = s.add_bonus(15)" }, { "stepNumber": 3, "title": "Inspect Updated Score", "instruction": "Run the flow and verify output 'result' returns 100 and 'updated_instance' reflects the modified score.", "conceptNote": "The returned score is 100 (85 + 15).", "nodeToInspect": "method_call", "pythonStatement": "print(new_score) # 100" } ], "starterGraph": { "name": "Method Call Starter Graph", "nodes": [ { "id": "inst_node", "node_type": "oop.instance", "position": { "x": 100, "y": 150 }, "data": { "label": "Alice85", "customData": { "class_name": "Student", "arg_1_val": "Alice", "arg_2_val": 85 } } }, { "id": "method_node", "node_type": "oop.method_call", "position": { "x": 380, "y": 150 }, "data": { "label": "AddBonus15", "customData": { "method_name": "add_bonus", "attribute_to_modify": "score", "operation": "increment", "default_arg": 15 } } } ], "edges": [ { "id": "e1", "source": "inst_node", "target": "method_node", "source_handle": "instance", "target_handle": "instance_in" } ] }, "exercise": { "type": "build_graph", "prompt": "Update a student's score by invoking an object method. Create a Student instance with initial score 85, and connect it to a Method Call node ('oop.method_call') calling 'add_bonus' with argument 15. Verify that the returned score evaluates to 100.", "targetRequirements": { "requiredNodeTypes": [ "oop.instance", "oop.method_call" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "result", "expectedValue": 100 } }, "hints": [ "Wire the instance output from oop.instance to instance_in on oop.method_call", "Set method_name to 'add_bonus' and arg to 15" ], "solutionExplanation": "Calling add_bonus(15) on the Student object increments its score from 85 to 100." } }, { "id": "lesson_23_files", "gate": "Gate G — Real Programs", "title": "23. File I/O: Reading & Writing Files", "shortDescription": "Learn how programs persist data to disk and read files using Python context managers.", "conceptExplanation": { "overview": "Real programs must read data from persistent storage (like config files, logs, or datasets) and save results back to disk. In Python, file operations use the 'with open(...) as f:' pattern, which ensures the file is automatically closed even if errors occur.", "keyPoints": [ "Use 'with open(path, mode)' to open files safely without resource leaks.", "Mode 'r' reads file contents, 'w' overwrites or creates a file, and 'a' appends.", "Always specify encoding='utf-8' for reliable cross-platform text processing." ], "whyItMatters": "Without file I/O, all calculations and state disappear as soon as the program finishes executing.", "pythonCode": "# Writing and Reading Files in Python\nwith open(\"output.txt\", \"w\", encoding=\"utf-8\") as f:\n f.write(\"Status: Complete\\nScore: 100\\n\")\n\nwith open(\"output.txt\", \"r\", encoding=\"utf-8\") as f:\n content = f.read()\nprint(content)" }, "guidedSteps": [ { "stepNumber": 1, "title": "Inspect the File Node", "instruction": "Add a File I/O node ('sys.file') to the canvas configured to read 'data.txt'.", "conceptNote": "File I/O nodes wrap Python's open() stream context manager.", "pythonStatement": "with open(\"data.txt\", \"r\", encoding=\"utf-8\") as _f:\n data = _f.read()" }, { "stepNumber": 2, "title": "Configure Mode & Content", "instruction": "In the Configuration Drawer, set mode to 'write' and content to 'ALLI Pipeline Output'.", "conceptNote": "Writing commits text directly to disk or virtual environment storage.", "pythonStatement": "_f.write(\"ALLI Pipeline Output\")" }, { "stepNumber": 3, "title": "Execute and Verify Output", "instruction": "Run the workflow and inspect the 'result' and 'status' output ports.", "conceptNote": "The output port returns confirmation and written byte counts.", "pythonStatement": "print(f\"Bytes written: {len(data)}\")" } ], "starterGraph": { "name": "File I/O Starter Graph", "nodes": [ { "id": "file_node", "node_type": "sys.file", "position": { "x": 160, "y": 150 }, "data": { "label": "WriteDataFile", "customData": { "file_path": "report.txt", "mode": "write", "content": "ALLI Pipeline Output" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Configure a File I/O node ('sys.file') to write 'ALLI Pipeline Output' to 'report.txt'. Verify that the node executes successfully and returns written status.", "targetRequirements": { "requiredNodeTypes": [ "sys.file" ], "expectedTargetOutput": { "portId": "status", "expectedValue": "success" } }, "hints": [ "Add a File I/O node from the palette or node menu", "Set file_path to 'report.txt' and mode to 'write'", "Set content to 'ALLI Pipeline Output'" ], "solutionExplanation": "The sys.file node executes a Python context manager write statement, returning status 'success'." } }, { "id": "lesson_24_apis", "gate": "Gate G — Real Programs", "title": "24. Web APIs: Consuming REST Endpoints", "shortDescription": "Learn how programs fetch live external data and interact with REST APIs over HTTP.", "conceptExplanation": { "overview": "Modern applications rarely live in isolation—they consume external data from weather services, payment gateways, and databases over the web using HTTP. In Python, the 'requests' library provides simple methods (GET, POST) to fetch resources and parse JSON payloads.", "keyPoints": [ "HTTP GET requests retrieve resources from a URL without modifying server state.", "HTTP POST requests send a JSON payload to create or process data on the server.", "Status code 200 means success; 404 means not found; 500 means server error.", "Use response.json() to convert raw HTTP responses into Python dictionaries and lists." ], "whyItMatters": "Web APIs connect your logic to real-time financial, scientific, and enterprise data around the globe.", "pythonCode": "import requests\n\n# Fetching student records from a REST API\nresponse = requests.get(\"https://api.example.com/students\", timeout=5)\nif response.status_code == 200:\n students = response.json()\n print(f\"Fetched {len(students)} records\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add an HTTP Request Node", "instruction": "Add an HTTP Request node ('api.http_request') to the canvas.", "conceptNote": "The node initiates outbound network requests using Python's requests library.", "pythonStatement": "response = requests.get(\"https://api.example.com/students\")" }, { "stepNumber": 2, "title": "Configure URL & Method", "instruction": "Set method to 'GET' and endpoint URL to 'https://api.example.com/students'.", "conceptNote": "GET requests retrieve structured data records.", "pythonStatement": "data = response.json()" }, { "stepNumber": 3, "title": "Inspect Status & Payload", "instruction": "Run the workflow and observe the 'status_code' (200) and 'is_success' (true) ports.", "conceptNote": "Successful HTTP requests return status codes in the 200-299 range.", "pythonStatement": "assert response.status_code == 200" } ], "starterGraph": { "name": "HTTP Request Starter Graph", "nodes": [ { "id": "http_node", "node_type": "api.http_request", "position": { "x": 160, "y": 150 }, "data": { "label": "FetchStudentsAPI", "customData": { "url": "https://api.example.com/students", "method": "GET", "timeout": 5 } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Configure an HTTP Request node ('api.http_request') to send a GET request to 'https://api.example.com/students'. Verify that status_code evaluates to 200 and is_success evaluates to true.", "targetRequirements": { "requiredNodeTypes": [ "api.http_request" ], "expectedTargetOutput": { "portId": "status_code", "expectedValue": 200 } }, "hints": [ "Place an HTTP Request node on the canvas", "Set method to 'GET' and URL to 'https://api.example.com/students'", "Run the flow and check status_code output" ], "solutionExplanation": "The HTTP Request node queries the endpoint and receives a 200 OK status code with parsed JSON records." } }, { "id": "lesson_25_databases", "gate": "Gate G — Real Programs", "title": "25. Databases: Querying & Filtering Records", "shortDescription": "Learn how programs filter, search, and aggregate structured records from in-memory datasets.", "conceptExplanation": { "overview": "In modern pipelines, programs query structured collections of records using filter predicates (e.g., status == 'active') to find specific items, compute counts, and project required fields. In ALLI, db.query serves as an in-memory collection query connector (filtering lists of record dictionaries) simulating table queries without needing external SQL/NoSQL database servers.", "keyPoints": [ "In-Memory Collection Query: Filters structured record dictionaries using key-value predicate matching.", "Predicate Matching: Checks attributes like 'status', 'score', or 'role' on each record dictionary.", "Query Operations: Supports 'find' (returns matching list), 'count' (number of matches), and 'first' (first matching record)." ], "whyItMatters": "Structured query filtering allows workflows to cleanly transform and inspect tabular data before saving or printing.", "pythonCode": "# In-Memory Dataset Querying in Python\nrecords = [\n {\"id\": 1, \"name\": \"Alice\", \"score\": 95, \"status\": \"active\"},\n {\"id\": 2, \"name\": \"Bob\", \"score\": 82, \"status\": \"active\"},\n {\"id\": 3, \"name\": \"Charlie\", \"score\": 70, \"status\": \"inactive\"},\n]\nactive_students = [r for r in records if r[\"status\"] == \"active\"]\nprint(f\"Active count: {len(active_students)}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Add a Database Query Node", "instruction": "Add a Database Query node ('db.query') to the canvas.", "conceptNote": "Connects to an in-memory structured dataset (list of record dicts) with zero external server dependencies.", "pythonStatement": "matched = [r for r in dataset if r.get(\"status\") == \"active\"]" }, { "stepNumber": 2, "title": "Configure Filter Parameters", "instruction": "Set table_name to 'students', filter_key to 'status', and filter_value to 'active'.", "conceptNote": "Filters records matching key == 'status' and value == 'active'.", "pythonStatement": "# Filtering for status == \"active\"" }, { "stepNumber": 3, "title": "Inspect Filter Count", "instruction": "Run the workflow and inspect the 'count' output port (expected: 2).", "conceptNote": "Two out of the three student records have status 'active'.", "pythonStatement": "count = len(matched) # 2" } ], "starterGraph": { "name": "Database Query Starter Graph", "nodes": [ { "id": "db_node", "node_type": "db.query", "position": { "x": 160, "y": 150 }, "data": { "label": "FilterActiveStudents", "customData": { "table_name": "students", "filter_key": "status", "filter_value": "active", "operation": "find" } } } ], "edges": [] }, "exercise": { "type": "build_graph", "prompt": "Query the students collection to filter for active records where filter_key is 'status' and filter_value is 'active'. Verify that the 'count' output returns 2.", "targetRequirements": { "requiredNodeTypes": [ "db.query" ], "expectedTargetOutput": { "portId": "count", "expectedValue": 2 } }, "hints": [ "Place a Database Query node on the canvas", "Set filter_key to 'status' and filter_value to 'active'", "Run the flow and verify count equals 2" ], "solutionExplanation": "The db.query node filters the student records for status='active', matching Alice and Bob (count: 2)." } }, { "id": "lesson_26_capstone", "gate": "Gate G — Real Programs", "title": "26. Capstone Pipeline: Building a Real Application", "shortDescription": "Combine data ingestion, error resilience, database querying, and output formatting into an end-to-end program.", "conceptExplanation": { "overview": "Congratulations on reaching the Level 2 Capstone! A real software system connects all 8 fundamental programming pillars: it ingests data from a file or API, shields execution with Try/Except error handling, queries and transforms records with functions and collections, and formats clean output logs.", "keyPoints": [ "Pillars 1-3: Input data and perform calculations.", "Pillars 4-5: Make control flow decisions and reuse logic through functions.", "Pillars 6-7: Organize collections into lists/dicts and encapsulate state with classes.", "Pillar 8: Ingest real-world data, guard against exceptions, and persist results." ], "whyItMatters": "Mastering the full pipeline transforms you from someone who merely connects visual blocks into an engineer who understands full-stack program architecture.", "pythonCode": "try:\n # 1. Ingest Data\n with open(\"report.txt\", \"w\", encoding=\"utf-8\") as f:\n f.write(\"Pipeline Started\")\n \n # 2. Query Active Records\n records = [\n {\"id\": 1, \"name\": \"Alice\", \"score\": 95, \"status\": \"active\"},\n {\"id\": 2, \"name\": \"Bob\", \"score\": 82, \"status\": \"active\"}\n ]\n active = [r for r in records if r[\"status\"] == \"active\"]\n \n # 3. Output Result\n print(f\"Processed {len(active)} active records successfully.\")\nexcept Exception as err:\n print(f\"Pipeline error: {err}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Ingest Data via File I/O", "instruction": "Add a File I/O node ('sys.file') writing 'Pipeline Started' to 'report.txt'.", "conceptNote": "Establishes persistent state on the filesystem.", "pythonStatement": "with open(\"report.txt\", \"w\") as f: f.write(\"Pipeline Started\")" }, { "stepNumber": 2, "title": "Filter Records with Database Query", "instruction": "Add a Database Query node ('db.query') filtering for status == 'active'.", "conceptNote": "Applies data transformation and filtering to structured records.", "pythonStatement": "active = [r for r in records if r[\"status\"] == \"active\"]" }, { "stepNumber": 3, "title": "Connect to Print Output", "instruction": "Connect the query 'count' port to a Print node to log the final pipeline summary.", "conceptNote": "Final output reflects the processed dataset count.", "pythonStatement": "print(f\"Active count: {count}\")" } ], "starterGraph": { "name": "Capstone Pipeline Starter Graph", "nodes": [ { "id": "file_step", "node_type": "sys.file", "position": { "x": 100, "y": 150 }, "data": { "label": "InitializeFile", "customData": { "file_path": "report.txt", "mode": "write", "content": "Pipeline Started" } } }, { "id": "db_step", "node_type": "db.query", "position": { "x": 360, "y": 150 }, "data": { "label": "FilterActive", "customData": { "table_name": "students", "filter_key": "status", "filter_value": "active", "operation": "find" } } }, { "id": "print_step", "node_type": "io.print", "position": { "x": 620, "y": 150 }, "data": { "label": "LogProcessedCount", "customData": { "prefix": "Processed active records: " } } } ], "edges": [ { "id": "e1", "source": "file_step", "target": "db_step", "source_handle": "out", "target_handle": "in" }, { "id": "e2", "source": "db_step", "target": "print_step", "source_handle": "count", "target_handle": "value" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct an end-to-end Capstone Pipeline: Use a File I/O node ('sys.file') to initialize state, pipe into a Database Query node ('db.query') filtering for 'active' records, and connect the query 'count' to a Print node ('io.print'). Verify that the printed result equals 2.", "targetRequirements": { "requiredNodeTypes": [ "sys.file", "db.query", "io.print" ], "requiredEdgeCount": 2, "expectedTargetOutput": { "portId": "result", "expectedValue": 2 } }, "hints": [ "Include sys.file, db.query, and io.print on the canvas", "Wire file out to db in, and db count to print value", "Run the flow and verify print output equals 2" ], "solutionExplanation": "The full pipeline initializes the file, queries active database records, and logs the count (2) via Print." } }, { "id": "lesson_27_third_party_packages", "gate": "Gate H — The Extensible Ecosystem", "title": "27. Third-Party Packages: Discovery & Dependencies", "shortDescription": "Explore Python's package ecosystem. Search the package registry, inspect dependencies, and declare pinned package versions for reproducible workflows.", "conceptExplanation": { "overview": "Python's superpower is its vast open-source package ecosystem hosted on PyPI. Real-world workflows rely on third-party libraries (such as requests, pandas, numpy) to extend core Python capabilities. In ALLI, the Package Registry (/packages) discovers and catalogs available packages with standardized metadata, while dependency pinning in requirements.txt ensures workflows execute identically across development, testing, and production environments.", "keyPoints": [ "Package Registry (/packages): Discovers standard library and external PyPI packages with version, category, and node count metadata.", "Dependency Pinning: Using exact version constraints (e.g., requests==2.31.0) prevents breaking changes from unexpected upstream updates.", "Manifest Generation: Workflows automatically synthesize requirements.txt manifests pairing declared dependencies with containerized Dockerfiles.", "Security Safeguards: Package names and versions are treated as untrusted inputs and validated against strict naming patterns." ], "whyItMatters": "Unpinned dependencies cause production builds to break when upstream libraries release incompatible changes. Strict version manifests ensure complete execution reproducibility.", "pythonCode": "# requirements.txt\n# requests==2.31.0\n\nimport requests\n\nresponse = requests.get(\"https://api.example.com/students\", timeout=5)\nprint(f\"Status: {response.status_code}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Discover Packages in Registry", "instruction": "Query the ALLI Package Registry (/packages) to inspect available libraries, their classification (stdlib vs. external), version tags, and install commands.", "conceptNote": "The registry provides unified metadata contracts including name, version, summary, and categories for standard and external libraries.", "pythonStatement": "import importlib.metadata; installed = [d.metadata[\"Name\"] for d in importlib.metadata.distributions()]" }, { "stepNumber": 2, "title": "Declare Pinned Dependencies", "instruction": "Attach external dependencies (such as requests==2.31.0) to your workflow blueprint to specify the exact versions needed for runtime execution.", "conceptNote": "Pinning dependencies guarantees that Docker builds and standalone Python runs use the exact tested library versions.", "pythonStatement": "import requests # Pinned dependency: requests==2.31.0" }, { "stepNumber": 3, "title": "Synthesize Manifest & Verify Parity", "instruction": "Generate the standalone Python script and requirements.txt manifest, confirming that external packages are cleanly pinned and standard libraries are excluded.", "conceptNote": "Standard libraries (like math, json, datetime) are excluded from requirements.txt, while external packages are pinned with exact version specifications.", "pythonStatement": "with open(\"requirements.txt\", \"w\") as f: f.write(\"requests==2.31.0\\n\")" } ], "starterGraph": { "name": "Third-Party Packages Starter", "dependencies": [ "requests==2.31.0" ], "nodes": [ { "id": "pkg_step", "node_type": "api.http_request", "position": { "x": 100, "y": 150 }, "data": { "method": "GET", "url": "https://api.example.com/students", "customData": { "method": "GET", "url": "https://api.example.com/students", "package": "requests", "version": "2.31.0" } } }, { "id": "print_step", "node_type": "io.print", "position": { "x": 450, "y": 150 }, "data": { "label": "Log Status" } } ], "edges": [ { "id": "e1", "source": "pkg_step", "target": "print_step", "source_handle": "status_code", "target_handle": "value" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct a workflow utilizing third-party package dependencies: Place an HTTP Request node ('api.http_request') configured with method 'GET' and URL 'https://api.example.com/students', pipe its 'status_code' to an Output Print node ('io.print'), and declare 'requests==2.31.0' in the workflow dependencies. Verify that status_code equals 200 and requirements.txt pins requests==2.31.0.", "targetRequirements": { "requiredNodeTypes": [ "api.http_request", "io.print" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "status_code", "expectedValue": 200 } }, "hints": [ "Include api.http_request and io.print on the canvas", "Wire status_code from http_request to value of print", "Verify that requirements.txt contains requests==2.31.0" ], "solutionExplanation": "The workflow queries the API using the pinned requests library (2.31.0) and prints status 200, generating a reproducible requirements.txt manifest." } }, { "id": "lesson_28_ast_introspection", "gate": "Gate H — The Extensible Ecosystem", "title": "28. Dynamic AST Introspection & Code Analysis", "shortDescription": "Learn how Python converts source text into an Abstract Syntax Tree (ast.parse) to inspect functions, imports, and variables without executing arbitrary code.", "conceptExplanation": { "overview": "Before Python code executes, the interpreter compiles source text into an Abstract Syntax Tree (AST)—a structural hierarchy representing expressions, statements, functions, and control flow. Using Python's built-in ast module (ast.parse, ast.walk, ast.NodeVisitor), developer tools inspect, lint, and validate code safely without executing it. In ALLI, AST inspection connects the visual graph to generated Python, confirming that visual nodes map 1:1 to generated AST symbols while detecting syntax errors and unapproved calls.", "keyPoints": [ "AST Parsing (ast.parse): Converts Python source text into a structured syntax tree without runtime execution.", "Visitor Pattern (ast.NodeVisitor): Traverses syntax nodes to identify functions (FunctionDef), classes (ClassDef), imports (Import), and calls (Call).", "Static Pre-Flight Validation: Detects syntax errors, unbalanced brackets, and dangerous functions (eval, exec) before execution starts.", "Graph-to-AST Parity: Compares visual nodes against AST call nodes, ensuring visual logic matches generated code 1:1." ], "whyItMatters": "Executing untrusted code directly is dangerous. AST inspection enables deterministic static analysis, powering linters, autocompletion, dynamic node generators, and code verification safely.", "pythonCode": "import ast\n\ncode = \"\"\"\nimport math\n\ndef calculate_circle_area(radius):\n return math.pi * (radius ** 2)\n\"\"\"\n\ntree = ast.parse(code)\nfunctions = [n.name for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)]\nprint(f\"Parsed functions: {functions}\")" }, "guidedSteps": [ { "stepNumber": 1, "title": "Parse Source Code into AST", "instruction": "Use Python's ast.parse() to transform a Python source string into an Abstract Syntax Tree and verify syntax integrity.", "conceptNote": "ast.parse() raises SyntaxError with exact line and column diagnostics if the input code is malformed.", "pythonStatement": "tree = ast.parse('import math\\nx = math.sqrt(49)')" }, { "stepNumber": 2, "title": "Traverse Nodes with ast.NodeVisitor", "instruction": "Subclass ast.NodeVisitor to inspect function definitions, imported modules, and callable expressions across the tree.", "conceptNote": "Visitor methods (visit_FunctionDef, visit_Call) are invoked automatically for each matching syntax element.", "pythonStatement": "funcs = [n.name for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)]" }, { "stepNumber": 3, "title": "Verify Graph-to-AST Parity", "instruction": "Cross-reference visual graph nodes against synthesized AST calls to confirm deterministic 1:1 parity and detect dropped logic.", "conceptNote": "Comparing visual nodes with AST symbols guarantees that no visual nodes are dropped or corrupted during code synthesis.", "pythonStatement": "assert len(funcs) > 0, 'AST must contain synthesized pipeline functions'" } ], "starterGraph": { "name": "AST Introspection Starter Graph", "nodes": [ { "id": "func_def", "node_type": "func.definition", "position": { "x": 100, "y": 150 }, "data": { "label": "ComputeArea", "customData": { "function_name": "compute_area", "parameters": "radius", "return_expr": "3.14159 * (radius ** 2)" } } }, { "id": "func_call", "node_type": "func.call", "position": { "x": 450, "y": 150 }, "data": { "label": "CallArea", "customData": { "function_name": "compute_area", "arguments": "7" } } } ], "edges": [ { "id": "e1", "source": "func_def", "target": "func_call", "source_handle": "out", "target_handle": "in" } ] }, "exercise": { "type": "build_graph", "prompt": "Construct a workflow and verify AST introspection: Place a Function Definition node ('func.definition') named 'compute_area', connect it to a Function Call node ('func.call'), and verify that the synthesized Python code produces valid AST syntax with both FunctionDef and Call symbols.", "targetRequirements": { "requiredNodeTypes": [ "func.definition", "func.call" ], "requiredEdgeCount": 1, "expectedTargetOutput": { "portId": "result", "expectedValue": 153.93791, "tolerance": 0.01 } }, "hints": [ "Add func.definition and func.call to the canvas", "Connect the function definition to the caller", "Verify that the AST inspection detects function compute_area and call compute_area" ], "solutionExplanation": "The visual graph synthesizes a Python function definition and call, successfully verified via AST inspection with zero syntax errors." } } ]
[
{
"id": "lesson_1_variables",
"gate": "Gate A — Fundamentals",
"title": "1. Variables & Memory Assignment",
"shortDescription": "Learn how programs name, store, and reuse values in memory.",
"conceptExplanation": {
"overview": "A variable is a named storage container in a computer's memory. Instead of re-typing numbers or text everywhere, you store a value once under a descriptive name (like 'user_age' or 'total_price') and pass it to other nodes.",
"keyPoints": [
"In Python, assignment uses '=': variable_name = value.",
"Variable names must start with a letter or underscore, not a number.",
"Wiring a variable into another node passes its stored value across the wire."
],
"whyItMatters": "Without variables, programs could not remember user inputs or calculate dynamic results.",
"pythonCode": "# Python Variable Assignment\nuser_age = 25\nprint(f\"Age stored: {user_age}\")"
},
"guidedSteps": [
{
"stepNumber": 1,
"title": "Create a Variable",
"instruction": "Add a Variable node or Constant Number node to the canvas.",
"conceptNote": "This allocates a piece of memory for your program.",
"pythonStatement": "score = 100"
},
{
"stepNumber": 2,
"title": "Assign a Name and Value",
"instruction": "Set the variable identifier to 'score' and value to 100 in the Configuration Drawer.",
"conceptNote": "Names should be lowercase with underscores (PEP 8 convention).",
"pythonStatement": "# score is now 100"
},
{
"stepNumber": 3,
"title": "Read the Output",
"instruction": "Connect the variable output to a Print node and run to verify the output.",
"conceptNote": "Data flows out of the right port into downstream nodes.",
"pythonStatement": "print(score)"
}
],
"starterGraph": {
"name": "Lesson 1 Starter",
"nodes": [
{
"id": "score_var",
"node_type": "alli.primitive.variable",
"position": {
"x": 100,
"y": 160
},
"data": {
"label": "score",
"customData": {
"var_name": "score",
"value": 100,
"type_hint": "int"
}
}
},
{
"id": "print_node",
"node_type": "alli.primitive.print",
"position": {
"x": 420,
"y": 160
},
"data": {
"label": "Print Result",
"customData": {
"prefix": ""
}
}
}
],
"edges": []
},
"exercise": {
"type": "build_graph",
"prompt": "Build a workflow that declares a variable or constant named 'score' with value 100, and connect it to a Print node.",
"targetRequirements": {
"requiredNodeTypes": [
"variable",
"constant",
"print"
],
"requiredEdgeCount": 1,
"expectedTargetOutput": {
"portId": "result",
"expectedValue": 100
}
},
"hints": [
"Drag a Number Constant or Variable node onto the canvas.",
"Open its inspector to set the value to 100.",
"Connect its output port to a Print node's input port."
],
"solutionExplanation": "The variable stores 100 in memory and passes it across the wire to the Print node, outputting 100."
}
},
{
"id": "lesson_2_data_types",