Refer to the exhibit. What is the result of running this code?
Refer to the exhibit. What is the result of running this code?
The code provided initializes a list 'vlans_list' with values [10, 20, 30] and then calls the function 'add_vlans' with this list. The 'add_vlans' function iterates over each element in the list and adds 100 to it. After the function is executed, the list is modified to [110, 120, 130]. Therefore, the result of running this code is a list of new VLANs is created.
vlans_list is a python list contaning the numbers: 10 , 20 and 30 (as integers) The function "add_vlans" scan the list and 100 to every item. The result should be: [110, 120, 130] So in my opinion the answer should be: [B] - A list of new VLANs is created.
Tested vlans_list = [10, 20, 30] def add_vlans(vlans): for i in range(len(vlans)): vlans[i]+=100 add_vlans(vlans_list) print(vlans_list) [110, 120, 130]
tried it online. the thing is that the vars are referenced and not sent by value. def main(): vlans_list = [10, 20, 30] add_vlans(vlans_list) print(vlans_list) def add_vlans(vlans): for i in range(len(vlans)): vlans[i]+=100 if _name_ == '_main_': main()
def main(): vlans_list = [10,20,30] add_vlans(vlans_list) print(vlans_list) def add_vlans(vlans): for i in range(len(vlans)): vlans[i]+=100 if __name__=='__main__': main() ===============OUTPUT=============== [110, 120, 130]
B is correct
i trust the comments, going with B
Run in Visual Studio. In this for it always throws an error. "NameError: name '_name_' is not defined" Could someone double check this please?
you are missing an _. there should be 2x_