Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ACTIVITY: References 5 print('Example: list products) WN 4 6 x = [1, 2, 3] + 3 print('before', x) x[0] = 10 print('after ',x) 1. Predict
ACTIVITY: References 5 print('Example: list products") WN 4 6 x = [1, 2, 3] + 3 print('before', x) x[0] = 10 print('after ',x) 1. Predict the console output. 2. Draw the frame and heap diagram, showing all the variables and values in the snippet. 3. Question: What does the change to x on line 5 do to x's value? Explain. ACTIVITY: References 6 print('Example: list products copy references') 3 OUAWN x = [[0, 1, 2]] * print('before', x) x[0][0] = 10 print (after ', x) 1. Predict the console output. 2. Draw the frame and heap diagram, showing all the variables and values in the snippet. 3. Question: What does the change to x on line 5 do to x's value? Explain. ACTIVITY: References 7 print('Example: functions and parameters') WN TO def change-params (a): a = a - 1 return a 7a = 5 8 b = 10 print('before', a, b) 10 b = change-params (a) 11 print('after ', a, b) 1. Predict the console output. 2. Draw the frame and heap diagram, showing all the variables and values in the snippet. 3. Question: How does line 10 affect the global variables a and b. Explain. 0000000000 000000000000 ACTIVITY: References 8 print('Example: functions and and immutable arguments') 500 OWN def swap-ints (x, y): print('inside swap_ints(), before', x, y) tmp = x x = y y = tmp print('inside swap_ints(), after ', x, y) 11 12 a = 3 b = 4 print('global scope, before', a, b) swap_ints (a, b) print('global scope, after', a, b) 1. Predict the console output. 2. Draw the frame and heap diagram, showing all the variables and values in the snippet. 3. Question: Did variables a and b get swapped? Explain. CMPT145 Lab 02. References, and Scope ACTIVITY. Reierelles print (Example: functions and and mutable arguments) def swap_in_list(a_list, i, j): tmp = a_list [1] a_list [1] = a_list [2] a_list [2] = tmp TO009 some_list = ['a', 'list', 'of', 'words'] print('before', some_list) swap_in_list (some_list, 1, 2) print('after ', some_list) 1. Predict the console output. 2. Draw the frame and heap diagram, showing all the variables and values in the snippet. 3. Question: Did the function call on line 10 affect the list some_list
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started