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 index 13b954eb9c146c1ac2b6cecd4a33797dff9dc99a..eda74ca2dafb2e6441616fe6c5ebd85fa7f990e6 100644 Binary files a/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.pdf 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 index e57b0809452ec97286b62a538189e9f7663fe48e..6e7fbf9dea72c9062ab2ef8ae8b1f76ee8298761 100644 Binary files a/s23/Common_to_all_lectures/06_Creating_Functions/06_Creating_Functions.ppt 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/w19.py b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w19.py new file mode 100644 index 0000000000000000000000000000000000000000..c6032e79c70a88995fcaeaa6182ba0ca457156d9 --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w19.py @@ -0,0 +1,8 @@ +print("A") + +def foo(): + print("B") +print("C") +foo() +print("D") +foo() diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w20.py b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w20.py new file mode 100644 index 0000000000000000000000000000000000000000..f14c9115370d4d7f5e9d49bd4866ed1c5003d66e --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w20.py @@ -0,0 +1,8 @@ +print("A") + +def foo(): + print("B") + print("C") +foo() +print("D") +foo() diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w21.py b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w21.py new file mode 100644 index 0000000000000000000000000000000000000000..57a3bbc33dd312b89b23b963f4ec431016c5661a --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w21.py @@ -0,0 +1,14 @@ +def func_c(): + print("C") + +def func_b(): + print("B1") + func_c() + print("B2") + +def func_a(): + print("A1") + func_b() + print("A2") + +func_a() diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w22.py b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w22.py new file mode 100644 index 0000000000000000000000000000000000000000..d7474ac7a5d8a66129088d979ec9068cec97be24 --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/lec-06/w22.py @@ -0,0 +1,8 @@ +def f(): + print("A") + return("B") + print("C") +print("D") +x = f() +print("E") +print(x) diff --git a/s23/Common_to_all_lectures/06_Creating_Functions/pytutor.py b/s23/Common_to_all_lectures/06_Creating_Functions/pytutor.py new file mode 100644 index 0000000000000000000000000000000000000000..2ee8f2497cfc7294916dd1c699379eea36455168 --- /dev/null +++ b/s23/Common_to_all_lectures/06_Creating_Functions/pytutor.py @@ -0,0 +1,34 @@ +import os, sys, json, subprocess +from subprocess import check_output + +PYTUTOR = "/Users/trh/g/OnlinePythonTutor/v5-unity/generate_json_trace.py" + +EMBEDDING = """ +<div id="DIV"></div> +<script type="text/javascript"> + var trace = TRACE; + addVisualizerToPage(trace, 'DIV', {startingInstruction: 0, hideCode: false, lang: "py3", disableHeapNesting: true}); +</script> +""" + +def run_pytutor(py): + try: + js = check_output(["python", PYTUTOR, py]) + except subprocess.CalledProcessError as e: + js = e.output + return json.dumps(json.loads(js)) + +def main(): + if len(sys.argv) < 2: + print("Usage: python pytutor.py file1.py [file2.py, ...]") + sys.exit(1) + + for py in sys.argv[1:]: + js = run_pytutor(py) + div = py.replace(".", "_").replace("/", "_") + code = EMBEDDING.replace("DIV", div).replace("TRACE", js) + print(code) + + +if __name__ == '__main__': + main()