Skip to content
Snippets Groups Projects
Commit 4d4faa60 authored by GURMAIL SINGH's avatar GURMAIL SINGH
Browse files

06_Creating Functions folder added

parent a45b0bea
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
File added
File added
<!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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment