- Demonstrate your ability to trace the flow of execution through multiple function calls.
- Predict the final output of a complete program.
- Correctly identify the values of local and global variables at specific points in the program.
Minor Assessment: Code Tracing & Scope Lab (5%)
Welcome, code detective! An essential skill for any programmer is the ability to read a piece of code and mentally "run" it to predict its behavior. This is called code tracing. It is the single most important skill for finding and fixing bugs.
Your Task
Carefully read the Python script in the image below. Do not run this code in an editor. The goal is to trace its execution manually. In a separate document, answer the five questions that follow.
The Code to Analyze:
The Questions to Answer:
- What is the very first line of output that will be printed to the screen when this program runs?
- What is the value printed for
local_xinsidefunction_a? - What is the value printed for
resultback in themainfunction? - What is the value printed for the local
xat the end of themainfunction? - What is the final value of the global
xthat is printed on the very last line?
Submission
Submit a document (e.g., Google Doc, Word file, or PDF) with your numbered answers to the "Unit 4 Code Tracing Lab" Assignment folder in D2L.
Get a piece of paper and make a table with two columns: "Global Scope" and "main() Scope". As you trace the code line by line, write down the variables in each column and update their values. This is the best way to keep track of everything!