Recent questions tagged output

1 1 vote
2 2 answers
147
147 views
A grid contains '$\texttt{s}$' for sand, '$\texttt{r}$' for rock, and $\texttt{None}$ for empty.The operation $\texttt{jumpdown(grid, x, n)}$ works on one column $\texttt...
1 1 vote
2 2 answers
124
124 views
Suppose $\texttt{zeroArray(3, 4)}$ creates a $2$D array with $3$ rows and $4$ columns, filled with zeros.Now consider:v = zeroArray(3, 4)Which expression correctly change...
2 2 votes
2 2 answers
128
128 views
Consider the following Python code:def group_by(s, fn): grouped = {} for x in s: key = fn(x) if key in grouped: grouped[key].append(x) else: grouped[key] = [x] return gro...
2 2 votes
2 2 answers
131
131 views
Consider the following Python code:def insert_items(s, before, after): index = 0 while index < len(s): if s[index] == before: s.insert(index + 1, after) index += 1 index ...
2 2 votes
3 3 answers
144
144 views
Consider the following Python code:def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) print(L1)What is...
2 2 votes
2 2 answers
238
238 views
A function $\texttt{deep_map(f, s)}$ replaces every non-list element $\texttt{x}$ inside a nested list $\texttt{​​​​​​​s}$ with $\texttt{f(x)}$.It modifies $\texttt{​​​​​...
2 2 votes
3 3 answers
223
223 views
A function $\texttt{shuffle(s)}$ takes a sequence $\texttt{s}$ with an even number of elements. It returns a new list by interleaving the first half of $\texttt{s}$ with ...
2 2 votes
3 3 answers
177
177 views
Consider the following Python code:s = [3] s.extend([4, 5]) s.extend([s.append(9), s.append(10)]) print(s)What is the output of the code above?[3, 4, 5, 9, 10][3, 4, 5, N...
2 2 votes
3 3 answers
198
198 views
Consider the following Python code:s = [9, 7, 8] a, b = s, s[:] print(a is s, b == s, b is s) print(a.pop()) print(a + b)What is the output of the code above?True True Tr...
2 2 votes
3 3 answers
239
239 views
Consider the following Python code:s = [6, 7, 8] print(s.append(6)) s.insert(0, 9) x = s.pop(1) s.remove(x) print(s)What is the output of the code above?None [9, 7, 8]Non...
6 6 votes
1 1 answer
417
417 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r4 = virfib_sq(4)What would be the outp...
4 4 votes
1 1 answer
241
241 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r3 = virfib_sq(3)What would Python disp...
3 3 votes
1 1 answer
206
206 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r2 = virfib_sq(2)What would be the outp...
3 3 votes
1 1 answer
202
202 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r1 = virfib_sq(1)What would be the outp...
2 2 votes
1 1 answer
229
229 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r0 = virfib_sq(0)What would be the outp...
2 2 votes
1 1 answer
226
226 views
Consider the following Python code:def total_first(t): if not t: return 0 return t[0][0] + total_first(t[1:]) data = [[2, 7], [5, 1], [3, 8], [4, 9]] print(total_first(da...
2 2 votes
1 1 answer
180
180 views
Consider the following Python code:def show(lst, i=0): if i == len(lst): return show(lst, i + 1) if lst[i] % 2 != 0: print(lst[i], end="") show([1, 2, 3, 4, 5])What is th...
2 2 votes
1 1 answer
165
165 views
Consider the following Python code:def count_greater(lst, v): if not lst: return 0 count = 1 if lst[0] v else 0 return count + count_greater(lst[1:], v) print(count_grea...
2 2 votes
1 1 answer
164
164 views
Consider the following Python code:def mystery(n): if n < 10: return n a = n // 10 b = n % 10 return mystery(a + b) print(mystery(678))What is the output of the code abov...
2 2 votes
1 1 answer
167
167 views
Consider the following Python code:def solve(n): if n <= 0: return 0 return n + solve(n - 2) print(solve(6), solve(5))What is the output of the code above?9 1212 912 12Re...
3 3 votes
1 1 answer
172
172 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None a = Node("A") b = Node("B") c = Node("C") d = Node("D") a.next ...
3 3 votes
1 1 answer
149
149 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None head = Node(20) tail = head new_first = Node(10) new_first.next...
3 3 votes
1 1 answer
136
136 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None n1 = Node(5) n2 = Node(10) n3 = Node(15) n4 = Node(20) n1.next ...
3 3 votes
2 2 answers
197
197 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None a = Node("A") b = Node("B") c = Node("C") a.next = b b.next = c...
4 4 votes
2 2 answers
180
180 views
Consider the following Python code:class Node: def __init__(self, value): self.value = value self.next = None n1 = Node(10) n2 = Node(20) print(n1.value, n1.next, n2.valu...
3 3 votes
1 1 answer
140
140 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None n1 = Node(10) n2 = Node(20) n3 = Node(30) n1.next = n2 n2.next ...
2 2 votes
1 1 answer
127
127 views
Consider the following Python code:class Batch: def __init__(self, name, count): self.name = name self.count = count def shift(self, other, n): self.count = self.count - ...
2 2 votes
1 1 answer
129
129 views
Consider the following Python code:class Box: def __init__(self, value): self.value = value def add(self, value): self.value = self.value + value value = value + 100 retu...
2 2 votes
1 1 answer
122
122 views
Consider the following Python code:class Account: def __init__(self, balance): self.balance = balance def deposit(self, amount): self.balance = self.balance + amount retu...
1 1 vote
1 1 answer
130
130 views
Consider the following Python code:class Faculty: def __init__(self, name, subject): self.name = name self.subject = subject f1 = Faculty("Sachin", "Python") f2 = Faculty...