Recent questions tagged goclasses-da-dpp

0 0 votes
1 1 answer
108
108 views
Consider the following Python code:def evaluate(x): try: if x == 0: return "zero" return "value" finally: x += 1 if x == 1: return "changed" print(evaluate(0), evaluate(2...
1 1 vote
1 1 answer
85
85 views
Consider the following Python code:def make_funcs(): funcs = [] total = 0 for i in range(3): def add(x, step=i): nonlocal total total += x + step return total funcs.appen...
1 1 vote
1 1 answer
85
85 views
Consider the following Python code:class Counter: count = [] def __init__(self, value): self.value = value def add(self): self.count.append(self.value) self.value += 1 re...
0 0 votes
1 1 answer
83
83 views
Consider the following Python code:nums = [1, 2, 3] it = iter(nums) first = next(it) nums.append(4) second = list(it) nums.append(5) third = list(it) print(first, second,...
0 0 votes
1 1 answer
96
96 views
Consider the following Python code:data = {"a": , "b": } x = data.setdefault("c", data["a"]) x.append(3) data["a"].append(4) data["b"] = data["a"][:] data["b"].append(5...
0 0 votes
1 1 answer
103
103 views
Consider the following Python code:data = [[1, 2, 3], [4, 5], [6]] result = [x for row in data for x in row if x % len(row) == 0] print(result)What is the output of the c...
1 1 vote
1 1 answer
94
94 views
Consider the following Python code:def make_list(): data = try: return data finally: data.append(2) result = make_list() print(result)What is the output of the code abo...
0 0 votes
1 1 answer
89
89 views
Consider the following Python code:funcs = [] for i in range(3): funcs.append(lambda x: x + i) result = [f(10) for f in funcs] print(result)What is the output of the code...
1 1 vote
1 1 answer
90
90 views
Consider the following Python code:values = [1, 2, 3] gen = (x * 2 for x in values) values.append(4) first = list(gen) values.append(5) second = list(gen) print(first, se...
1 1 vote
1 1 answer
88
88 views
Consider the following Python code:grid = [[0] * 2] * 3 grid[0] = 5 grid = [7, 8] grid [0] = 9 print(grid)What is the output of the code above?[[0, 5], [9, 5], [7, 8]][...
1 1 vote
1 1 answer
163
163 views
Consider the following Python code:x = 0 y = 5 result = (x != 0) and (y / x 1) or (y < 10) print(result)What is the output of the code above?TrueFalseZeroDivisionErrorNo...
1 1 vote
1 1 answer
125
125 views
Consider the following Python code:words = ["apple", "bat", "car", "dog"] result = {i: word.upper() for i, word in enumerate(words) if len(word) == i + 3} print(result)Wh...
0 0 votes
1 1 answer
105
105 views
Consider the following Python code:def add_item(value, box=[]): box.append(value) return box a = add_item(10) b = add_item(20, []) c = add_item(30) print(a, b, c)What is ...
1 1 vote
1 1 answer
104
104 views
Consider the following Python code:total = 0 for num in range(1, 7): if num % 2 == 0: continue if num == 5: break total += num else: total += 100 print(total)What is the ...
1 1 vote
1 1 answer
118
118 views
Consider the following Python code:matrix = [[1, 2], [3, 4], [5, 6]] copy_matrix = matrix[:] copy_matrix[0] = 99 copy_matrix = [7, 8] print(matrix, copy_matrix)What is ...
1 1 vote
2 2 answers
169
169 views
Consider the following Python code:nums = [1, 2, 3, 4, 5] result = [n * 2 if n % 2 == 0 else n + 1 for n in nums if n 2] print(result)What is the output of the code abov...
0 0 votes
1 1 answer
119
119 views
Consider the following Python code:text = "bookkeeper" count = 0 for i in range(len(text) - 1): if text[i] == text[i + 1]: count += 1 print(count)What is the output of th...
0 0 votes
1 1 answer
113
113 views
Consider the following Python code:def update(nums): nums.append(nums[-1] + 1) nums = nums[1:] nums[0] = 99 return nums values = [3, 4, 5] result = update(values) print(v...
1 1 vote
1 1 answer
111
111 views
Consider the following Python code:data = {"a": 2, "b": 3} for key in ["a", "c", "b", "a"]: data[key] = data.get(key, 0) + 1 print(data)What is the output of the code abo...
0 0 votes
1 1 answer
114
114 views
Consider the following Python code:items = [10, 20, 30, 40, 50] part = items[1:4] part = 99 items += part[0] print(items, part)What is the output of the code above?[10,...
3 3 votes
3 3 answers
247
247 views
What value will $\texttt{x}$ store after the execution of the code below?x = 4 x = 2Value of $\texttt{x}$ multiplied by $\texttt{2}$Square of $\texttt{x}$Value of $\text...
2 2 votes
2 2 answers
179
179 views
Consider the following Python code:scores = {"Ali": 8, "Mia": 10} scores["Ali"] += 2 scores["Noah"] = scores["Mia"] - 3 print(scores)What is the output of the code above?...
2 2 votes
2 2 answers
192
192 views
Consider the following Python code:total = 0 for n in [1, 2, 3, 4]: if n % 2 == 0: total += n else: total -= n print(total)What is the output of the code above?
2 2 votes
3 3 answers
191
191 views
Consider the following Python code:word = "python" result = word[1:4] + word[-1] print(result)What is the output of the code above?ythnythopythnthon
3 3 votes
1 1 answer
145
145 views
Consider the following Python code:nums = [2, 4, 6, 8] nums = nums + 3 nums.append(10) nums.pop(0) print(nums)What is the output of the code above?[2, 7, 6, 8, 10][7, 6...
2 2 votes
1 1 answer
164
164 views
Consider the following Python code:def append_val(val, my_list=[]): my_list.append(val) return my_list list1 = append_val(10) list2 = append_val(20, []) list3 = append_va...
1 1 vote
1 1 answer
144
144 views
Consider the following Python code:m = [[1, 2], [3]] n = m.copy() r = [m[0], n ] * 2 m[0].remove(2) n += [4] r = r + [5]What is the result of evaluating $\texttt{r}$?[...
0 0 votes
1 1 answer
124
124 views
Consider the following Python code:x = [ , [2, 3]] y = [x[0]] * 3 + x[1:] y[0].append(4) x[0] = x[0] + [5] y[3].pop()What is the result of evaluating $\texttt{y}$?[[1, 4,...
0 0 votes
1 1 answer
120
120 views
Consider the following Python code:a = [[0], ] b = a[:] c = a * 2 b[0].append(2) c = c + [3] a .append(4)What is the result of evaluating $\texttt{c}$ ?[[0, 2], [1, 4]...
0 0 votes
1 1 answer
124
124 views
Consider the following Python code:p = [ , ] q = p * 2 q[0].append(3) q = q + [4] p .extend(q[0])What is the result of evaluating $\texttt{q}$ ?[[1, 3, 4], [2, 1, 3], ...