Recent questions tagged programming-in-python

3 3 votes
1 1 answer
213
213 views
What is the output of the below code snippet?for var1, var2 in (1,2),(3,4): print(var1 + var2, end = " ")(a) 4 6(b) 10(c) 3 7(d) TypeError
1 1 vote
1 1 answer
211
211 views
What is the output of the below code snippet?result = 0 list1 = [10,20,30] list2 = [1,2] for num in range(len(list1)): for num in range(len(list2)): result += list1[num] ...
0 0 votes
1 1 answer
187
187 views
What is the output of the below code snippet?def move(list1, list2): for num in list1: list2.append(num) list1.remove(num) list1 = [1,2,3,4,5] list2 = [10] move(list1, li...
5 5 votes
1 1 answer
402
402 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...
3 3 votes
1 1 answer
226
226 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...
2 2 votes
1 1 answer
196
196 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...
2 2 votes
1 1 answer
192
192 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...
1 1 vote
1 1 answer
215
215 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...
1 1 vote
1 1 answer
217
217 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...
1 1 vote
1 1 answer
170
170 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...
1 1 vote
1 1 answer
158
158 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...
1 1 vote
1 1 answer
157
157 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...
1 1 vote
1 1 answer
159
159 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...
2 2 votes
1 1 answer
165
165 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 ...
2 2 votes
1 1 answer
142
142 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...
2 2 votes
1 1 answer
129
129 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 ...
2 2 votes
2 2 answers
189
189 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...
3 3 votes
2 2 answers
172
172 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...
2 2 votes
1 1 answer
135
135 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 ...
1 1 vote
1 1 answer
121
121 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
122
122 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
117
117 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
125
125 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...
1 1 vote
1 1 answer
148
148 views
Consider the following Python code:class Batch: def __init__(self, students): self.students = students def add_students(self, n): self.students = self.students + n return...
2 2 votes
1 1 answer
128
128 views
Consider the following Python code:class Course: pass c = Course() c.name = "GATE DA" c.marks = 30 c.marks = c.marks + 5 print(c.name, c.marks)What is the output of the c...
2 2 votes
1 1 answer
117
117 views
Consider the following Python code:class Counter: def __init__(self): self.value = 0 def increase(self): self.value = self.value + 1 c1 = Counter() c2 = Counter() c1.incr...
1 1 vote
1 1 answer
110
110 views
Consider the following Python code:class Faculty: def teach(self): return self.subject + " class" f = Faculty() f.subject = "Python" print(f.subject) print(f.teach())What...
2 2 votes
1 1 answer
109
109 views
Consider the following Python code:class Student: pass s1 = Student() s2 = Student() s1.name = "Asha" s2.name = "Ravi" print(s1.name, s2.name, s1 is s2)What is the output...
2 2 votes
1 1 answer
151
151 views
Consider the following Python code:A = {1, 2, 3, 4, 5} B = {4, 5, 6} C = {x * x for x in A if x % 2 == 1} print(sorted(A & B), sorted(A - B), sorted(C | {4}))What is the ...
1 1 vote
1 1 answer
105
105 views
Consider the following Python code:fruits = {"apple", "banana"} fruits.add("apple") fruits.update(["cherry", "apple"], "go") fruits.discard("mango") fruits.remove("banana...