diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.pdf b/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.pdf new file mode 100644 index 0000000000000000000000000000000000000000..13b954eb9c146c1ac2b6cecd4a33797dff9dc99a Binary files /dev/null and b/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.pdf differ diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.ppt b/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.ppt new file mode 100644 index 0000000000000000000000000000000000000000..e57b0809452ec97286b62a538189e9f7663fe48e Binary files /dev/null and b/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.ppt differ diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet-solution.pdf b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet-solution.pdf new file mode 100644 index 0000000000000000000000000000000000000000..29a883754dd82916d9102d0fef14bbe5b2809698 Binary files /dev/null and b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet-solution.pdf differ diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.docx b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.docx new file mode 100644 index 0000000000000000000000000000000000000000..24a9d793ebfccc8718085adf1e3eb1479a9f60af Binary files /dev/null and b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.docx differ diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.pdf b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.pdf new file mode 100644 index 0000000000000000000000000000000000000000..fc3b5792b2b1c57aa2f1985e86d2130f9e764d21 Binary files /dev/null and b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06-worksheet.pdf differ diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06.html b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06.html new file mode 100644 index 0000000000000000000000000000000000000000..193f615a3588fff070eb0bd9174865e6b00a9ee3 --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06.html @@ -0,0 +1,62 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + +<!-- + Python Tutor: https://github.com/pgbovine/OnlinePythonTutor/ + Copyright (C) Philip Guo (philip@pgbovine.net) + LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt +--> + +<head> + <title>CS 220 - Function Scope</title> + + <script type="text/javascript" src="../js/pytutor-embed.bundle.js" charset="utf-8"></script> + +</head> + +<body style="background-color: white;"> + +<!-- +To auto-generate examples: + +python pytutor.py lec-08/practice1.py lec-08/practice2.py lec-08/practice3.py lec-08/lesson1.py lec-08/lesson2.py lec-08/lesson3.py lec-08/lesson4.py lec-08/lesson5.py lec-08/lesson6.py lec-08/lesson7.py lec-08/lesson8.py lec-08/lesson9.py lec-08/lesson10.py +--> + +<h1>CS 220 - Tracing Functions</h1> + +<h2>Worksheet Problem 19</h2> + +<div id="lec-06_w19_py"></div> +<script type="text/javascript"> + var trace = {"code": "print(\"A\")\n\ndef foo():\n print(\"B\")\nprint(\"C\")\nfoo()\nprint(\"D\")\nfoo()\n", "trace": [{"ordered_globals": [], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 1, "event": "step_line"}, {"ordered_globals": [], "stdout": "A\n", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 3, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 5, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 6, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 3, "event": "call"}, {"ordered_globals": ["foo"], "stdout": "A\nC\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": ["__return__"]}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "return"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 7, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\nD\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 8, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\nD\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 3, "event": "call"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\nD\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\nD\nB\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": ["__return__"]}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "return"}, {"ordered_globals": ["foo"], "stdout": "A\nC\nB\nD\nB\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 8, "event": "return"}]}; + addVisualizerToPage(trace, 'lec-06_w19_py', {startingInstruction: 0, hideCode: false, lang: "py3", disableHeapNesting: true}); +</script> + + +<h2>Worksheet Problem 20</h2> +<div id="lec-06_w20_py"></div> +<script type="text/javascript"> + var trace = {"code": "print(\"A\")\n\ndef foo():\n print(\"B\")\n print(\"C\")\nfoo()\nprint(\"D\")\nfoo()\n", "trace": [{"ordered_globals": [], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 1, "event": "step_line"}, {"ordered_globals": [], "stdout": "A\n", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 3, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 6, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 3, "event": "call"}, {"ordered_globals": ["foo"], "stdout": "A\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 5, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\n", "func_name": "foo", "stack_to_render": [{"frame_id": 1, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f1", "ordered_varnames": ["__return__"]}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 5, "event": "return"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 7, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 8, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 3, "event": "call"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 4, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\nB\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": []}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 5, "event": "step_line"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\nB\nC\n", "func_name": "foo", "stack_to_render": [{"frame_id": 2, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "foo", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "foo_f2", "ordered_varnames": ["__return__"]}], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 5, "event": "return"}, {"ordered_globals": ["foo"], "stdout": "A\nB\nC\nD\nB\nC\n", "func_name": "<module>", "stack_to_render": [], "globals": {"foo": ["REF", 1]}, "heap": {"1": ["FUNCTION", "foo()", null]}, "line": 8, "event": "return"}]}; + addVisualizerToPage(trace, 'lec-06_w20_py', {startingInstruction: 0, hideCode: false, lang: "py3", disableHeapNesting: true}); +</script> + +<h2>Worksheet Problem 21</h2> +<div id="lec-06_w21_py"></div> +<script type="text/javascript"> + var trace = {"code": "def func_c():\n print(\"C\")\n\ndef func_b():\n print(\"B1\")\n func_c()\n print(\"B2\")\n\ndef func_a():\n print(\"A1\")\n func_b()\n print(\"A2\")\n\nfunc_a()\n", "trace": [{"ordered_globals": [], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 1, "event": "step_line"}, {"ordered_globals": ["func_c"], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {"func_c": ["REF", 1]}, "heap": {"1": ["FUNCTION", "func_c()", null]}, "line": 4, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b"], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {"func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null]}, "line": 9, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 14, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "", "func_name": "func_a", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 9, "event": "call"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "", "func_name": "func_a", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 10, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\n", "func_name": "func_a", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 11, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\n", "func_name": "func_b", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 4, "event": "call"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\n", "func_name": "func_b", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 5, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\n", "func_name": "func_b", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 6, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\n", "func_name": "func_c", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}, {"frame_id": 3, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_c", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_c_f3", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 1, "event": "call"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\n", "func_name": "func_c", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}, {"frame_id": 3, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_c", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_c_f3", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 2, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\n", "func_name": "func_c", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}, {"frame_id": 3, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "func_c", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_c_f3", "ordered_varnames": ["__return__"]}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 2, "event": "return"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\n", "func_name": "func_b", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 7, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\nB2\n", "func_name": "func_b", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": false, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}, {"frame_id": 2, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "func_b", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_b_f2", "ordered_varnames": ["__return__"]}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 7, "event": "return"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\nB2\n", "func_name": "func_a", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": []}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 12, "event": "step_line"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\nB2\nA2\n", "func_name": "func_a", "stack_to_render": [{"frame_id": 1, "encoded_locals": {"__return__": null}, "is_highlighted": true, "is_parent": false, "func_name": "func_a", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "func_a_f1", "ordered_varnames": ["__return__"]}], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 12, "event": "return"}, {"ordered_globals": ["func_c", "func_b", "func_a"], "stdout": "A1\nB1\nC\nB2\nA2\n", "func_name": "<module>", "stack_to_render": [], "globals": {"func_a": ["REF", 3], "func_c": ["REF", 1], "func_b": ["REF", 2]}, "heap": {"1": ["FUNCTION", "func_c()", null], "2": ["FUNCTION", "func_b()", null], "3": ["FUNCTION", "func_a()", null]}, "line": 14, "event": "return"}]}; + addVisualizerToPage(trace, 'lec-06_w21_py', {startingInstruction: 0, hideCode: false, lang: "py3", disableHeapNesting: true}); +</script> + +<h2>Worksheet Problem 22</h2> +<div id="lec-06_w22_py"></div> +<script type="text/javascript"> + var trace = {"code": "def f():\n print(\"A\")\n return(\"B\")\n print(\"C\")\nprint(\"D\")\nx = f()\nprint(\"E\")\nprint(x)\n", "trace": [{"ordered_globals": [], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {}, "heap": {}, "line": 1, "event": "step_line"}, {"ordered_globals": ["f"], "stdout": "", "func_name": "<module>", "stack_to_render": [], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 5, "event": "step_line"}, {"ordered_globals": ["f"], "stdout": "D\n", "func_name": "<module>", "stack_to_render": [], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 6, "event": "step_line"}, {"ordered_globals": ["f"], "stdout": "D\n", "func_name": "f", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "f", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "f_f1", "ordered_varnames": []}], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 1, "event": "call"}, {"ordered_globals": ["f"], "stdout": "D\n", "func_name": "f", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "f", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "f_f1", "ordered_varnames": []}], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 2, "event": "step_line"}, {"ordered_globals": ["f"], "stdout": "D\nA\n", "func_name": "f", "stack_to_render": [{"frame_id": 1, "encoded_locals": {}, "is_highlighted": true, "is_parent": false, "func_name": "f", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "f_f1", "ordered_varnames": []}], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 3, "event": "step_line"}, {"ordered_globals": ["f"], "stdout": "D\nA\n", "func_name": "f", "stack_to_render": [{"frame_id": 1, "encoded_locals": {"__return__": "B"}, "is_highlighted": true, "is_parent": false, "func_name": "f", "is_zombie": false, "parent_frame_id_list": [], "unique_hash": "f_f1", "ordered_varnames": ["__return__"]}], "globals": {"f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 3, "event": "return"}, {"ordered_globals": ["f", "x"], "stdout": "D\nA\n", "func_name": "<module>", "stack_to_render": [], "globals": {"x": "B", "f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 7, "event": "step_line"}, {"ordered_globals": ["f", "x"], "stdout": "D\nA\nE\n", "func_name": "<module>", "stack_to_render": [], "globals": {"x": "B", "f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 8, "event": "step_line"}, {"ordered_globals": ["f", "x"], "stdout": "D\nA\nE\nB\n", "func_name": "<module>", "stack_to_render": [], "globals": {"x": "B", "f": ["REF", 1]}, "heap": {"1": ["FUNCTION", "f()", null]}, "line": 8, "event": "return"}]}; + addVisualizerToPage(trace, 'lec-06_w22_py', {startingInstruction: 0, hideCode: false, lang: "py3", disableHeapNesting: true}); +</script> + + + + + +</body> +</html>