Document Details

QuickerForeshadowing403

Uploaded by QuickerForeshadowing403

L.J. Institute of Engineering and Technology

2024

Tags

python programming programming test questions practice book

Summary

This is a practice book for a Python programming course, specifically for the third semester. Exam-style questions are presented along with options to aid with learning and preparation.

Full Transcript

L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024...

L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks 1 1 Which character is used in Python to make a single line comment? D 1 / // ! # 2 1 What will be the output of print(type(2**5)) in python? A 1 3 1 What will be the output of print(type("LJU")) in python? C 1 4 1 What will be the output of print(type(3*5/5)) in python? B 1 5 1 If x=3.123, then int(x) will give ? B 1 1 3 4 3.12 Which one of the following is correct way of declaring and initialising a variable, x with value 5? int x 6 1 C 1 int x=5 x=5 declare x=5 x=5 7 1 Which of the following is an invalid statement? B 1 abc = 1,000,000 a b c = 1000 2000 3000 a,b,c = 1000, 2000, 3000 a_b_c = 1,000,000 8 1 Which of the following is invalid? D 1 _x = 1 __x = 1 __x__ = 1 None of the mentioned 9 1 Which of the following cannot be a variable? B 1 __in__ in it __it__ 10 1 Which of the following is an invalid variable? B 1 char_1 1st_char oopec _ What happens when '2' == 2 is executed? 11 1 B 1 True False ValueError TypeError What will be the output of this program? 12 1 _ = '1 2 3 4 5 6' D 1 SyntaxError: EOL while scanning string literal SyntaxError: invalid syntax NameError: name '_' is not defined 123456 print(_) The following is displayed by a print function call. Select all of the function calls that result in this output. print('''tom print('tom tom 13 1 C 1 \nsam print(”’tomsamharry”’) print(‘tom\nsam\nharry’) sam sam \nharry''') harry') harry What will be the output of the following program on execution? None python 14 1 print(print(print("python"))) B 1 None None python Error python None 15 1 Which is the correct operator for power(Xy)? B 1 X^y X**y X^^y None of the mentioned 16 1 What is the answer to this expression, 34 % 3 is? B 1 7 1 0 5 What will be the output of the following program on execution? a=0 b=6 17 1 B 1 0 6 True False x=(a or b) or ((a and a) or (a and b)) print(x) What will be the output of the following program on execution? a=0 b=6 18 1 D 1 0 6 True False x=(a or b) or ((a and a) or (a and b)) y=not(x) print(y) What will be the output of this program? 19 1 B 1 True ** False / True 1.0 0 Error print(True ** False / True) What is the average value of the following Python code snippet? 1. >>>grade1 = 80 20 1 D 1 84.5 86 84.0 85.0 2. >>>grade2 = 90 3. >>>average = (grade1 + grade2) / 2 Which of the following error occurs when you execute the following Python code? 21 1 C 1 Type Error Value Error Name Error Syntax Error apple = mango What is the output of this expression, 3*1**3? 22 1 B 1 1 3 9 27 Select option that will print: 23 1 A 1 print(‘hello-‘ + ‘how-are-you’) print(‘hello’, ‘how’, ‘are’, ‘you’) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’) hello-how-are-you In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed. 24 1 D 1 A = 27 // 5 A = int(27 / 5) A = 27 % 5 All of the mentioned >>>A = 27 ? 5 objective is to make sure A has an integer value. Which of the following is not a comparison operator in Python? 25 1 C 1 >= 0 B 1 True False Error No output z=115): 4 5 6 5 83 2 c=c+n-1 B 1 16 11 7 10 n=n-1 else: break print(n) print(c) How many times will the loop run? i=2 84 2 A 1 2 3 1 0 while(i>0): i=i-1 L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks How many times will the condition will be checked? i=2 85 2 B 1 2 3 1 0 while(i>0): i=i-1 What will be the output of the following Python code? i=1 while True: 1 1 86 2 if i%3 == 0: C 1 2 Error None of these 2 break 3 print(i) i+=1 What is the value of the var after the for loop completes its execution var = 10 for i in range(10): for j in range(2, 10, 1): if var % 2 == 0: 87 2 continue B 1 20 21 10 30 var += 1 var+=1 else: var+=1 print(var) What will be the output of the following Python code? 88 2 for i in range(0,2,-1): C 1 Hello Hello Hello No Output Error print("Hello") 89 2 Which of the following is a valid for loop in Python? B 1 for(i=0; i < n; i++) for i in range(0,5): for i in range(0,5) for i in range(5) Which of the following sequences would be generated by the given line of code? 90 2 C 1 5 4 3 2 1 0 -1 543210 531 None of the above range (5, 0, -2) When does the else statement written after loop execute? When break statement is executed in the 91 2 B 1 When loop condition becomes false Else statement is always executed None of the above loop What is the output of the following for loop and range() function 92 2 for num in range(-2,-5,-1): D 1 -2, -1, -3, -4 -2, -1, 0, 1, 2, 3, -2, -1, 0 -2, -3, -4, print(num, end=", ") What will be the output of the following code? x = 12 93 2 C 1 12 12 Error None of the above for i in x: print(i) What is the value of x after the following nested for loop completes its execution x=0 for i in range(10): 94 2 B 1 99 90 100 101 for j in range(-1, -10, -1): x += 1 print(x) What is the output of the following range() function 95 2 for num in range(2,-5,-1): C 1 2, 1, 0 2, 1, 0, -1, -2, -3, -4, -5 2, 1, 0, -1, -2, -3, -4 None of these print(num, end=", ") What is the value of x x=0 96 2 while (x < 100): D 1 101 99 None of the above, this is an infinite loop 100 x+=2 print(x) What is the output of the following nested loop 9 for num in range(10, 14): 11 10 12 10 for i in range(2, num): 12 11 13 97 2 B 1 11 if num%i == 1: 13 12 14 12 print(num) 14 13 15 break What will be the output of the following Python code? i=1 while True: 1 1 98 2 if i%3 == 0: A 1 2 Error None of these 2 break 3 print(i) i += 1 What will be the output of the following Python code? 1 1 i=1 2 3 while True: 1 3 5 99 2 if i%2 == 0: D 1 1 2 4 7 break 5 9 print(i) 6… 11 … i += 2 L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be the output of the following Python code? i=2 2 while True: 4 2 2 100 2 if i%3 == 0: B 1 6 Error 4 3 break 8 print(i) 10.. i += 2 What will be the output of the following Python code? i=1 1 1 while False: 3 2 101 2 if i%2 == 0: D 1 1 None of these 5 3 break 7.. 4.. print(i) i += 2 What will be the output of the following Python code? True = False 102 2 while True: D 1 TRUE FALSE None Error print(True) break What will be the output of the following Python code? 103 2 B 1 0 No output Error None of mentioned for i in range(0): print(i) What will be the output of the following Python code? 104 2 C 1 0.0 1.0 01 Error None of mentioned for i in range(2.0): print(i) What will be the output of the following Python code? 0 105 2 B 1 0.0 1.0 Error None of mentioned for i in range(int(2.0)): 1 print(i) What will be the output of the following Python code? 106 2 for i in range(float('inf')): D 1 0.0 0.1 0.2 0.3 … 0123… 0.0 1.0 2.0 3.0 … None of mentioned print (i) What will be the output of the following Python code? 0 for i in range(5): 0 1 0 1 if i == 5: 1 2 1 2 break 2 107 2 A 1 3 2 3 else: 3 4 3 4 print(i) 4 5 4 5 else: Here Here print("Here") What will be the output of the following Python code? 0 for i in range(10): 0 1 0 1 if i == 5: 1 2 1 2 break 2 108 2 C 1 3 2 3 else: 3 4 3 4 print(i) 4 5 4 5 else: Here Here print("Here") What will be the output of the following Python code snippet? 0 1 x=2 0 109 2 B 1 2 0 Error for i in range(x): -2 3 x -= 2 4 print (x) What will be the output of the following Python code snippet? 0 0 x=2 1 0 3 1 110 2 for i in range(x): C 1 2 1 4 2 x += 1 3 3 print (x) 4.. What will be the output of the following Python code? i=0 while i < 5: 0 0 print(i) 1 111 2 A 1 1 Error None of these i += 1 2 2 0 if i == 3: break else: print(0) L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be the output of the following Python code? i=0 0 0 0 1 while i < 3: 1 112 2 C 1 1 2 Error print(i) 3 2 2 i += 1 0 0 else: print(0) What will be the output of the following Python code? 0 1 x=2 0 113 2 B 1 2 0 error for i in range(x): -2 3 x -= 2 4… print (x) 114 2 The continue statement can be used in? D 1 while loop for loop do-while Both A and B What is the output of following python code? int("Enter value of x:") 115 2 for in range[0, 10]: D 1 They are unequal They are equal 0,1,2,3,4,5,6,7,8,9 SyntaxError print("They are equal") else: print( "They are unequal") What is the output of following python code? 116 2 a=5 A 1 yes no ZeroError SyntaxError b = 5.0 print('yes') if (a == b) else 'no' What is the output of following python code? a=b=0 117 2 if (a = b): D 1 yes 0 ZeroError SyntaxError print(0) else: print('otherwise') What is the output of following python code? Step = 3 for e in range(0, step): 118 2 B 1 3 NameError ZeroError SyntaxError if e%2==0: print('hello') else: print('goodbye') What will be the output of the following Python code? x = 123 119 2 C 0.5 123 123 Type Error Key Error for i in x: print(i) What is the output of the following snippet? theSum = 0 120 2 for count in range(2, 11, 2): C 1 25 20 30 23 theSum += count print(theSum) What will be the output of the following snippet? a = True b = False c = False if not a or b: 121 2 print (1) C 1 1 2 3 4 elif not a or not b and c: print (2) elif not a or b or not b and a: print (3) else: print (4) L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be the output of the following Python code? var = 10 for i in range(5): for j in range(2, 3, 1): if var%2 == 0: 122 2 break B 1 19 20 21 14 var += 1 var+=1 else: var+=1 print(var) What will be output of following code? A=70 if A>90: print('Grade A') elif A>70 and A50 and A35 and A=3600: hour=seconds//3600 seconds %= 3600 print(hour,"hours",end=" ") 124 2 A 1 1 hours 50 seconds 1 hours 0 minutes 50 seconds 1 hours 50 minutes 0 hours 0 minutes 3650 seconds if seconds>=60: minute=seconds//60 seconds %= 60 print(minute,"minutes",end=" ") if seconds>0: print(seconds,"seconds") What will be output of following code? A=0 for i in range(4): if i%2==0: pass 125 2 C 1 4 3 2 0 else: continue break A+=1 print(A) What will be the output of the following code snippet? count = 0 while(True): if count % 3 == 0: 126 2 A 1 0 3 6 9 12 15 0123 0369 0 3 6 9 12 print(count, end = " ") if(count > 15): break; count += 1 What is the output of the following code? a = True b = False c = True if not a or b: 127 2 print ("a") B 1 a b c d elif not a or not b and c: print ("b") elif not a or b or not b and a: print ("c") else: print ("d") What does the following code print? if 5 + 5 == 10: print("TRUE") TRUE TRUE 128 2 D 0.5 TRUE FALSE else: FALSE TRUE print("FALSE") print("TRUE") L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks Which of the following will evaluate to true? I. True and False 129 2 II. False or True D 0.5 I II I, II II, IV III. False and (True or False) IV. True and (True or False) What is the output of the following nested loop for num in range(26, 30): for i in range(2, num): 130 2 C 0.5 26,27,28 26,27,28,29 26,27,28,29, 27,29 if num%i == 1: print(num, end=’,’) break What is the value of the var after the for loop completes its execution: var = 10 for i in range(10): for j in range(2, 10, 1): if var % 2 == 0: 131 2 var += 1 D 1 20 21 30 31 continue var+=1 else: var+=1 print(var) What should be the output of the following python code snippet: a=5 b=7 c=2 if a>b: 132 2 a,b = b,a C 1 2,5,7 7,5,2 2 5 7, 7 5 2, if a>c: a,c = c,a if b>c: b,c = c,b print(a,b,c,end=",") What is the value of x after the following nested for loop completes its execution x=0 for i in range(1,10): 133 2 A 0.5 81 90 80 99 for j in range(-1, -10, -1): x += 1 print(x) What is the value of x x=0 134 2 while (x < 100): D 0.5 98 99 100 102 x+=3 print(x) What will be the output of the following program. if (9 < 0) and (0 < -9): print("hello") 135 2 A 0.5 Indentation error hello good bad elif (9 > 0) or False: print("good") else: print("bad") What is the output of the following code? c=1 s=0 while c) 'object'>) class C(A, B): def rk(self): pass r = C() print(C.__mro__) What is the output of the following code? import numpy as np a=np.array([1,2,3,4]) 637 9 A 1 (4, ) -4 (1,0) (1,4) print(a.shape) What is wrong with this program? import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) cannot reshape array of size 8 into shape 638 9 A 1 cannot reshape array of size 7 into shape (3,3) there is no function called array None of these newarr = arr.reshape(3, 3) (3,3) print(newarr) L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be output for the following code? Import numpy as np A=np.array([[[1,2], [4,3]], [[3,5], [6,4]]]) (array([0, 1], dtype=int64), array([1, 1], (array([1,2], dtype=int64), array([0, 1], (array([1, 1], dtype=int64), array([0, 1], 639 9 A 1 Error x=np.where(A==4) dtype=int64), array([0, 1], dtype=int64)) dtype=int64), array([1, 1], dtype=int64)) dtype=int64)) print(x) What will be the MRO for class P in program given below: class A: pass class B: pass class C: pass class X(A,B): 640 9 D 1 P,Z,Y,X,A,B,C,Object P,Z,A,Y,C,A,B,X,A,B,Object P,Z,A,Y,C,B,X,Object P,Z,Y,C,X,A,B,Object pass class Y(C,A,B): pass class Z(A): pass class P(Z,Y,X): pass What will be output for the following code? from abc import ABC,abstractmethod class Father(ABC): @abstractmethod def display(self): pass def play(self): Child class 641 9 print('Abstract class') D 1 Child class Abstract class Error Abstract class class Son(Father): def play(self): print('Child class') A=Son() A.play() What will be output for the following code? import numpy as np [[1 3] [[ 1 3 6] [ arr1=np.array ([[1,3], [14,20], [5,6]]) 642 9 B 1 [14 20] [14 20 9] [1 3 6 14 20 9 5 6 12] arr2=np.array ([, , ]) [5 6]] [ 5 6 12]] ] arr=np.concatenate((arr1,arr2),axis=1) print(arr) What will be output for the following code? import numpy as np a = np.array([[1,0,3],[0,1,4]]) 643 9 b = np.array([[0,2,3],[0,1,5]]) D 1 15 20 25 10 c = np.array([[1,2,0],[0,1,1]]) d=a+b+c print (d[1,2]) What will be the output of the following Python code? class A(): def disp(self): print("C disp()") class C(): def disp(self): A disp() 644 9 A 1 C disp() A disp() B disp() print("A disp()") C disp() class B(A,C): def dis(self): print("B disp()") obj = B() obj.disp() L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be the output of the following Python code? class A: def __init__(self,x=3): self._x = x class B(A): def __init__(self): 645 9 super().__init__(5) B 1 3 5 53 35 def display(self): print(self._x) def main(): obj = B() obj.display() main() What will be the output of the following code: class A: def __init__(self,x): self.x = x def count(self,x): self.x = self.x-2 class B(A): def __init__(self, y=0): 646 9 A.__init__(self, 3) C 1 30 31 3 -1 Error self.y = y def count(self): self.y -= 1 def main(): obj = B() obj.count() print(obj.x, obj.y) main() What will be printed? import numpy as np a = np.array([1,2,3,5,8]) b = np.array([0,3,4,2,1]) 647 9 B 1 10 55 33 35 c=a+b+2*b c = c*a print (c) What will be the output of the following code: class P: pass class Q: pass class R(P,Q): pass [__main__.T, __main__.S, __main__.R, (__main__.T, __main__.S, __main__.P, __main__.Q, (__main__.T, __main__.S, __main__.R, (__main__.T, __main__.S, __main__.Q, 648 9 C 1 class S(Q): __main__.P, __main__.Q] __main__.R, object) __main__.P, __main__.Q, object) __main__.R, __main__.P, object) pass class T(S,R): pass a=T() T.__mro__ What will be the output of the following code: class Demo: def __init__(self): self.x = 1 def change(self): self.x = 10 return self.x 649 9 class Demo_derived(Demo): A 1 5 10 1 2 def change(self): self.x*=5 return self.x def main(): obj = Demo_derived() print(obj.change()) main() L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be the output of the following code: import numpy as np [[ 1 2 3] [[[ 1 2 3]] [[[ 1 2 3] arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]) [ 4 5 6] [[ 4 5 6]] [ 4 5 6]] 650 9 B 1 Error newarr = arr.reshape(4, 1, -1) [ 7 8 9] [[ 7 8 9]] [[ 7 8 9] print(newarr) [10 11 12]] [[10 11 12]]] [10 11 12]]] What will be output for the following code? import numpy as np arr=np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]) [[[4 2] [[[1 3] arr1=np.array([[[4,3,2],[7,10,15]],[[6,1,2],[8,7,9]]]) [[[1 2 3] 651 9 C 1 [7 15]]] Value Error [4 6]]] newarr=np.concatenate((arr,arr1),axis=1) [4 5 6]]] x=newarr[:1:,:2:,:3:2] y=np.sort(x) print(y) What will be output for the following code? import numpy as np [ [[3 4 5] [, 652 9 arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) A 1 ] [8 9 10]] ] [[3 8]] print(arr[0:, -3:-2]) What will be output for the following code? import numpy as np arr=np.array([[[1,2,3],[4,5,6]],[[6,5,3],[4,2,1]]]) 653 9 A 1 (2,1,2) (1,2,4) (2,2,3) (2,3,2) x=arr[0:2,::2,::2] print(x.shape) What will be output for the following code? import numpy as np arr1 = np.array([[[1, 2], [3, 4]]]) 654 9 arr2 = np.array([[[5, 6], [7, 8]]]) A 1 (1,4,2) (1,2,4) (2,2,2) (4,2) arr = np.concatenate((arr1, arr2), axis=1) print(arr.shape) What will be the output of the following Python code? class P1: def hi(self): print("hi P1") class P2: def hi(self): print("hi P2") class C1(P1): 655 9 pass D 1 hello C1 hi C1 hello GC hello C2 class C2(P1): def hi(self): print("hello C2") class GC(C1,C2): pass gc=GC() gc.hi() What will be the output of the following Python code? class P1: def hello(self): print("hi P1") class P2: def hi(self): print("hi P2") class C1(P1): 656 9 pass A 1 hi P1 hi C1 hello GC hello C2 class C2(P1): def h(self): print("hello C2") class GC(C1,C2): pass gc=GC() gc.hello() What will be output for the following code? import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) (array([0, 2, 4, 6], 657 9 A 1 arr([1, 3, 5, 7],) All of these x = np.where(arr%2 == 1) dtype=int64),) print(x) L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What is the Output of the Following Code? class A: def __init__(self, x=5): self.x = x class der(A): 658 9 def __init__(self, y=3): C 1 12 35 53 Error super().__init__() self.y = y def main(): obj = der() print(obj.x, obj.y) main() What will be output for the following code? 659 9 import numpy as np D 1 16 17 18 27 arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) print(arr[0,1],arr[1,1]) What will be output for the following code? 660 9 import numpy as np A 1 [3 2 1 0] [1 2 3 0] [0 1 2 3] 0123 arr = np.array([3, 2, 0, 1]) print(np.sort(arr)[::-1]) What will be output for the following code? arr1 = np.array([[1,2],[5,6]]) arr2 = np.array([[3,4],[7,8]]) arr=np.concatenate((arr1,arr2)) 661 9 D 1 [7 8] 7 4 8 for i in arr: for j in i: if(j%2==0): newarr=j print(newarr) What will be printed? import numpy as np a = np.array([1,2,3,5,8]) 662 9 C 1 18 15 30 20 b = np.array([0,3,4,2,1]) c=a*b c=c+a print ( c + c ) What is the output of following code? 663 9 arr = np.array([1,2,3,4,5,6,7,8]) A 1 1 2 3 (2,) arr.reshape(2,4) print(arr.ndim) What will be output for the following code? import numpy as np [[10 12 13] [[10 10 10] 664 9 a=np.array([,,]) A 1 [12 14 15] [14 14 14] ValueError TypeError b=np.array([[5,7,8]]) [13 15 16]] [16 16 16]] print(b+a) What will be output for the following code? class A: def hello(self): print("1",end=",") def hello(self): print("2",end=",") class B(A): 665 9 A 1 3,2,3,2, 3,2 2,3,2,3, 3, def __init__(self): self.hello() def hello(self): print("3",end=",") super().hello() b=B() b.hello() L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number question_text MCQ Answer option A option B option C option D No. ks What will be output for the following code? class A: money=5000 def __init__(self): self.money+=A.money 666 9 class B(A): A 1 12000 7000 5000 3000 def display(self): self.money+=2000 print(self.money) obj=B() obj.display() What will be output for the following code? class A: a=20 def __init__(self): self.a+=10 class B(A): a=15 667 9 def buy(self): C 1 30 20 40 10 pass class C(B,A): a=30 def buy(self): print(self.a) obj=C() obj.buy() Program to demonstrate the use of inheritance 668 9 4 Program to demonstrate the use of multiple inheritance 669 9 4 Program to demonstrate the use of multilevel inheritance 670 9 4 Implement the following hierarchy. The Book function has name, n (number of authors), authors (list of authors), publisher, ISBN, and year as its data members and the derived class has course as its data member. The derived class 671 9 6 method overrides (extends) the methods of the base class. Implement the following hierarchy. The Staff function has name and salary as its data members, the derived class 672 9 Teaching has subject as its data member and the class NonTeaching has department as its data member. The derived class 6 method overrides (extends) the methods of the base class. Create a class called Student, having name and email as its data members and _init_(self, name, email) and putdata(self) as bound methods. The _init_ function should assign the values passed as parameters to the requisite variables. The putdata function should display the data of the student. Create another class called PhDguide having name, email, and students as its data members. Here, the students variable is the list of students under the guide. The PhDguide class should have four 673 9 bound methods: _init_, putdata, add, and remove. The _init_ method should initialize the variables, the putdata should 6 show the data of the guide, include the list of students, the add method should add a student to the list of students of the guide and the remove function should remove the student (if the student exists in the list of students of that guide) from the list of students. Program to demonstrate the issue of invoking __init__() in case of multiple inheritance 674 9 4 Write program that has a class point. Define another class location which has two objects (Location and Destination) of 675 9 class point. Also define function in Location that prints reflection of Destination on the x axis. 6 Write a program that overload the + operator so that it can add two object of class fraction 676 9 4 Write a program that overload the * operator so that it can add two object of class fraction 677 9 4 Write a program to find the distance between two points in cartesian cordinate system 678 9 4 Write a program to find the slope between two points in cartesian cordinate system 679 9 4 Create a class student with following member attributes: roll no, name, age and total marks. Create suitable methods for 680 9 reading and printing member variables. Write a python program to overload ‘==’ operator to print the details of students 6 having same marks. Write a program to create a class called Data having “value” as its data member. Overload the (>) and the ( operator. Execute the method resolution order of the Circle class. Write a python program to demonstrate the use of super() method to call the method of base class. 693 9 4 Create a class called Matrix containing constructor that initialized the number of rows and number of columns of a new Matrix object. The Matrix class has methods for each of the following: 1. get the number of rows 2. get the number of columns 694 9 9 3. set the elements of the matrix at given position (i,j) 4. adding two matrices. If the matrices are not addable, “ Matrices cannot be added” will be displayed.(Overload the addition operation to perform this) 5. Multiplying the two matrices. If the matrices are not multiplied, “ Matrices cannot be multiplied” will be displayed.(Overload the addition operation to perform this) L.J Institute of Engineering and Technology, Ahmedabad. FCSP-1 Practice Book (SEM-III )_ODD-2024 Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book. Sr. mar unit_number

Use Quizgecko on...
Browser
Browser