Recent questions tagged python-programming

4 4 votes
1 1 answer
293
293 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
296
296 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
257
257 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...
3 3 votes
3 3 answers
442
442 views
What will be output in Line-1 and Line-2 in the following code?a = 256 b = 256 print(a is b) #Line-1 c = 257 d = 257 print(c is d) #Line-2 
1 1 vote
1 1 answer
344
344 views
Consider the following Python code:def append_to_lst(val, lst=[]): lst.append(val) return lst print(append_to_lst(1)) print(append_to_lst(2)) print(append_to_lst(...
1 1 vote
0 0 answers
259
259 views
Let $G=(V,E)$ be a directed graph, and let $G^R$ denote the graph obtained by reversing all the edges of $G$.Which of the following statements is/are TRUE?If a vertex $v$...
0 0 votes
2 2 answers
344
344 views
A binary tree has the following traversals:Preorder traversal$: P, Q, S, E, R, F, G$ Inorder traversal$: S, Q, E, P, F, R, G$ Which of the following statement(s) is/are T...
0 0 votes
1 1 answer
256
256 views
Consider the following Python code:def outer(): x = [] def inner(val): x.append(val) return x return innerNow consider:f1 = outer() f2 = outer...
1 1 vote
2 2 answers
368
368 views
Consider the following function:def fun(L, i = 0): if i >= len(L) - 1: return 0 if L[i] L[i + 1]: L[i], L[i + 1] = L[i + 1], L[i] return ...
1 1 vote
3 3 answers
335
335 views
Consider the following function:def mystery(n): if n <= 0: return 1 else: return mystery(n - 1) + mystery(n - 2)If the function is called as $\tex...
7 7 votes
3 3 answers
3.9k
3.9k views
Consider the following Python declarations of two lists.\[\begin{array}{l}A=[1,2,3] \\B=[4,5,6]\end{array}\]Which one of the following statements results in $\mathrm{A}=[...
2 2 votes
2 2 answers
3.1k
3.1k views
​​​​​​Consider the following Python code snippet.\[\begin{array}{l}\mathrm{A} = \{ \text{”this”, ”that”} \} \\\mathrm{B} = \{ \text{”that”, ”other”} \} \\\mathrm{C} = \{ ...
4 4 votes
3 3 answers
3.5k
3.5k views
Consider the following Python code snippet.def f(a,b): if (a==0): return b if (a%2==1): return 2*f((a-1)/2,b) return b+f(a-1,b) print(f(15,10))The value printed by the co...