PB Python-I Sem III 2024
PB Python-I Sem III 2024
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
a=5
b=10
49 1 B 0.5 522 521 525 5 10 5
c=1
print(a**c, b//a, c%a)
Which of the following is invalid?
50 1 A 0.5 1x=1 x1=1 __x__=1 _x=1
What is the output of this expression, 3**1**3/True?
51 1 C 0.5 1 3 3.0 27
What will be the output of the following program on execution?
a=0
52 1 A 0.5 True 1 0 False
b=5
a or b ==5 or True + 7 -4 * 3
What will be the output of the following program on execution?
a=50
53 1 D 0.5 0 60 50 Error
b=60
print((a and b)/False)
Write a Python program to add 2 Numbers with user input.
54 1 4
Write a Python program to find the area of Circle.
55 1 4
Write a Python program to find the area of Triangle.
56 1 4
Write a Python program to calculate the area of a trapezoid.
57 1 4
Write a Python program to calculate surface volume and area of a cylinder.
58 1 4
Write a Python program to convert Fahrenheit to Celsius and vice versa.
59 1 7
Write a python code to demonstrate calculator functionality.
60 1 7
Write a python program to convert Days into Years, Months and Days. (Ex: if input of Days = 370 then output will be,
61 1 7
years=1, months=0 and days = 5).
Write a Python program to convert hours into minutes and seconds (Ex : input of hours = 6 then output will be, minutes =
62 1 7
360 and seconds = 21600 ).
Write a Python program to find an integer exponent x such that a^x = n.
Input:
a = 2 : n = 1024
Output:
63 1 10 4
Input:
a = 3 : n = 81
Output:
4
Which one of the following if statements will not execute successfully: if (1, 2): if (1, 2): if (1, 2):
64 2 D 1 if (1, 2): print('foo')
print('foo') print('foo') print('foo')
Which of the following are valid if/else statements in Python, assuming x and y are defined appropriately: if x < y: print('foo')
65 2 A 1 elif y < x: print('bar') if x < y: if x > 10: print('foo') if x < y: print('foo') else: print('bar') None of mentioned
else: print('baz')
What does the following code print?
if 4 + 5 == 10:
TRUE
print("TRUE") TRUE FALSE
66 2 C 1 TRUE FALSE
else: FALSE TRUE
TRUE
print("FALSE")
print("TRUE")
What does the following code print?
x = -10 The negative number -10 is not valid here. It will cause an error because every if
67 2 B 1 This is always printed The negative number -10 is not valid here
if x < 0: This is always printed statement must have an else statement.
print("The negative number ", x, " is not valid here.")
print("This is always printed")
Which of the following is true about the code below?
x=3
if (x > 2): x will always equal 0 after this code if x is greater than 2, the value in x will be doubled if x is greater than 2, x will equal 0 after this
68 2 C 1 None of mentioned
x = x * 2; executes for any value of x after this code executes code executes
if (x > 4):
x = 0;
print(x)
Which one of the following is a valid Python if statement?
69 2 A 1 if a>=2 : if (a >= 2) if (a => 22) if a >= 22
What keyword would you use to add an alternative condition to an if statement?
70 2 C 1 else if elseif elif None of the above
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
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
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
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?
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
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
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.
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
i,j=1,4
while True:
141 2 if(i%7==0 or j%9==0): C 1 59 67 69 79
break
i+=1
j+=1
print(i,j)
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
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Write a program to find the maximum number among the three input numbers.
154 2 7
Write a python program to read three numbers (a,b,c) and check how many numbers between ‘a’ and ‘b’ are divisible by
158 2 4
‘c’.
Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
159 2 4
Write a Python program to print the multiplication table of given number by user.
160 2 4
Write a program to take 10 values from keyboard using loop and print their average on the screen
163 2 4
Write a program to print prime numbers between given interval from user
167 2 7
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Draw a pattern:
* * * *
169 2 * * * 7
* *
*
Draw a pattern using a python program:
*
170 2 * * 7
* * *
* * * *
Draw a pattern:
* * * *
171 2 * * * 7
* *
*
Draw a pattern using a python program:
1 2 3 4 5
1 2 3 4
172 2 7
1 2 3
1 2
1
Draw a pattern using a python program:
1
173 2 1 2 3
1 2 3
1 2 3 4
Draw a pattern using a python program:
1
174 2 2 2 3
3 3 3
4 4 4 4
Draw a pattern using a python program:
*
175 2 # # 4
* * *
# # # #
Draw a pattern using a python program:
1
176 2 0 1 4
1 0 1
0 1 0 1
Draw a pattern using a python program:
1
177 2 1 2 4
1 2 3
1 2 3 4
Draw a pattern using a python program:
1
178 2 2 2 4
3 3 3
4 4 4 4
Draw a pattern using a python program:
*
179 2 # # 4
* * *
# # # #
Gross Pay, Annual Income and Income Tax Calculator
Write a Python Program to make the gross pay, annual income and income tax calculator using following data.
The gross pay consists of Basic Pay, House Rent Allowance (hra), Dearness Allowance (dra), other allowances and
professional tax and provident fund.
Gross Pay= Basic Pay+ House Rent Allowance (hra) + Dearness Allowance (dra) +other allowances +Transport Allowance
(TA)– Professional tax –Employees’ Provident fund (EPF)
Basic Pay for different grade levels are indicated in table given.
The Professional tax remains constant and that is equal to 200 Rs. for each grade levels and each month.
House Rent Allowance (hra) varies as per the city- For Class 1 Cities it is 0.3 times of Basic Pay of each grade levels, for Class
2 Cities it is 0.2 times of Basic Pay of each grade levels, for Class 3 Cities it is 0.1 times of Basic Pay of each grade levels,
Dearness Allowance (dra)= 0.5 times of Basic Pay of each grade levels, Other allowances are given in table which varies
according to different grade levels, Provident Fund= 0.11 times of Basic Pay for each grade levels, Transport Allowance
remains constant as 900 Rs. for each levels.
For different grade pays:
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
180 2 9
Write a python program to print all numbers between 1 and 100 (including 1 and 100) that are both, Disarium and
Harshad numbers.
A number is said to be a Disarium number when the sum of its digit raised to the power of their respective positions
becomes equal to the number itself.
For example, 175 is a Disarium number as follows:
11+ 72 + 53 = 1+ 49 + 125 = 175
181 2 5
A harshad number is a number that is divisible by the sum of its digits. E.g., the number 18 is a harshad number, because
the sum of the digits 1 and 8 is 9 (1 + 8 = 9), and 18 is divisible by 9.
Grading scheme:
2 marks for writing correct code for checking Disarium number
2 marks for writing correct code for checking Harshad number
1 mark for writing correct code for only printing those numbers that are both, Disarium and Harshad numbers.
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
Ask the user to enter 10 test scores. Write a program to do the following:
a)If user enters score greater than 100, then give warning to user that entered score is more than 100 and take that
input again from user. b)Print out the highest and lowest scores.
c)Print out the average of the scores. d)Print out the second largest score.
e)Drop the two lowest scores and print out the average of the rest of them.
Note: Use of Python Data structures like string, list, tuple etc. and their inbuilt function is not allowed.
For Ex.
If Input is like following:
Enter Test Score: 80
Enter Test Score: 65
Enter Test Score: 98
Enter Test Score: 70
Enter Test Score: 93
182 2 Enter Test Score: 130 6
Entered score is more than hundred, so enter again
Enter Test Score: 95
Enter Test Score: 50
Enter Test Score: 40
Enter Test Score: 75
Enter Test Score: 72
Write a python program to swap first and last digits of a number using loop.
184 2 5
(for example: input = 123456 then output=623451)
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
185 2 4
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
189 2 6
Write a program that enters a single digit integer number and produces all possible 6-digit numbers for which the product
of their digits is equal to the entered number.
Example: "number" → 2
•111112 → 1 * 1 * 1 * 1 * 1 * 2 = 2
190 2 •111121 → 1 * 1 * 1 * 1 * 2 * 1 = 2 4
•111211 → 1 * 1 * 1 * 2 * 1 * 1 = 2
•112111 → 1 * 1 * 2 * 1 * 1 * 1 = 2
•121111 → 1 * 2 * 1 * 1 * 1 * 1 = 2
•211111 → 2 * 1 * 1 * 1 * 1 * 1 = 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
Write a Python program that prompts the user to enter numbers and stops only when the user enters “stop”. After this,
print the minimum even, maximum even, average of even number, minimum odd, maximum odd, average of odd number
from among all the numbers entered by the user.
Note: You are not allowed to use any built-in structures like lists, tuples, etc. or any built-in functions like max, min, sum
Example: input and output
enter number or q for'stop:'-1
enter number or q for'stop:'-5
191 2 5
enter number or q for'stop:'9
enter number or q for'stop:'2
enter number or q for'stop:'4
enter number or q for'stop:'6
enter number or q for'stop:'stop
Output:
for even 6 2 4.0 (max, min, avg)
for odd 9 -5 1.0 (max, min, avg)
What is the output of the following function call?
def fun1(name, age=20):
192 3 A 1 Emma 25 Emma 20 Emma, 25 Emma, 20
print(name, age)
fun1('Emma', 25)
What will be the output of the following Python code?
a=10
b=20
def change():
global b 10 45 10
193 3 A 1 Syntax Error
a=45 56 56 20
b=56
change()
print(a)
print(b)
What will be the output of the following Python code?
def display(b, n):
while n > 0:
194 3 A 1 zzz zz An exception is executed Infinite Loop
print(b,end="")
n=n-1
display('z',3)
What will be the output of the following Python code?
def fun(x,y,z):
195 3 A 1 432 24000 430 No output
return x + y + z
print(fun(2,30,400))
What will be the output of the following Python code?
def func():
global value
196 3 value = "Local" A 1 Local Global None Error
value = "Global"
func()
print(value)
What will be the output of the following Python code?
def say(message, times = 1):
Hello Hello Hello Hello
197 3 print(message * times) A 1
WorldWorldWorldWorldWorld World 5 World,World,World,World,World HelloHelloHelloHelloHello
say('Hello')
say('World', 5)
What will be the output of the following Python code?
def sub(a,b):
-100 100 100 -100
198 3 print(a-b) A 1
100 100 -100 -100
sub(100,200)
sub(200,100)
What will be the output of the following Python code?
x = 50
def func(x):
x is 50 x is 50 x is 50
print('x is', x)
199 3 A 1 Changed local x to 2 Changed local x to 2 Changed local x to 2 None of the mentioned
x=2
x is now 50 x is now 2 x is now 100
print('Changed local x to', x)
func(x)
print('x is now', x)
What will be the output of the following Python code?
def C2F(c):
212 212.0 567
200 3 return c * 9/5 + 32 B 1 None of the mentioned
32 32.0 98
print(C2F(100))
print(C2F(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
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
def test_fib(n):
for i in range(n+1):
global num_fib_calls
num_fib_calls = 0
print('fib of', i, '=', fib(i))
print('fib called', num_fib_calls, 'times.')
What will be the output of the following Python code?
def f(p, q, r):
global s
p = 10
q = 20
214 3 A 1 10 20 30 40 10 20 30 4 1 2 3 40 1234
r = 30
s = 40
print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)
If number of arguments in function definition and function call does not match, then which type of error is returned?
215 3 D 1 NameError ImportError funError TypeError
What will be the output of the following Python code?
def power(x, y=3):
r=1
for i in range(y):
216 3 C 0.5 33 99 27 27 9 27
r=r*x
return r
print(power(3),end=" ")
print(power(3,3))
Select which is true for Python function:
i) A function is a code block that only executes when called and always returns a value.
217 3 C 1 only i only ii I & ii I & iii
ii) A function only executes when it is called and we can reuse it in a program.
iii) Python doesn’t support nested function
What will be the output of the following Python code?
def function1(var1=7,var2=5):
var1=2
var3=var1*var2
218 3 A 0.5 12 10 18 25
return var3
var2=6
var1=3
print(function1(var1,var2))
What will be the output of the following Python code?
def fun(a=5,b=10,c):
219 3 D 0.5 400 1 5 25 2 5 400 2 30 Error
print(a**2,b//a,c**1)
fun(20,c=30)
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
Write a Python function to display the Fibonacci sequence till the given user input n.
225 3 4
Write a Python program to accept two numbers and check it for odd or even number
227 3 3
Write a Python program to check whether the given no is Armstrong or not using user defined function.
228 3 3
Write a Python program to demonstrate the function of finding sum and average of first n natural numbers.
231 3 3
Write a Python program to demonstrate the function of finding multiplication of first n natural numbers.
232 3 3
Write a Python program to find reverse of given number using user defined function.
233 3 3
Write your own python program for computing square roots that implements Newton’s Method. Use of inbuilt function,
math library or x**0.5 is not allowed.
Newton Method is a category of guess-and-check approach. You first guess what the square root might be and then see
how close your guess is. You can use this information to make another guess and continue guessing until you have found
the square root (or a close approximation to it). Suppose x is the number we want the root of and guess is the current
guessed answer. The guess can be improved by using (guess+ x/guess)/2 as the next guess.
234 3 5
The program should -
1.Prompt the user for the value to find the square root of (x) and the number of times to improve the guess.
2.Starting with a guess value of x/2, your program should loop the specified number of times applying Newton’s method
and report the final value of guess.
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
What will the below Python code will return? It returns the first index position of the It returns the last index position of the
It returns the first index position of the first It returns the last index position of the last
239 4 str1="save paper,save trees" B 1 last occurance of "save" in the given first occurance of "save" in the given
occurance of "save" in the given string str1. occurance of "save" in the given string str1.
str1.find("save") string str1. string str1.
Which of the following will give "Aryan" as output?
240 4 D 1 print(str1[-9:-12]) print(str1[-12:-7]) print(str1[-13:-6]) print(str1[-13:-8])
str1="Vishv,Aryan,Devarsh"
What will following Python code return?
241 4 str1="LJ University" A 1 13 12 11 14
print(len(str1))
What will be the output of the following Python statement?
242 4 B 1 cde cdef bcdef def
"abcdef"[2:8]
What will be the output of the following Python statement?
243 4 D 1 Error Output equivalent to print ‘new\nline’ new line newline
print('new' 'line')
What will be the output of the following Python code?
str1="hello world"
244 4 C 1 hello world dlrow olleh hello world
str1[::-1]
x = ['ab', 'cd']
245 4 A 1 [‘ab’, ‘cd’] [‘AB’, ‘CD’] [None, None] none of the mentioned
for i in x:
i.upper()
print(x)
What will be the output of the following Python code?
x = 'abcd'
246 4 C 1 abcd 0123 error None of mentioned
for i in range(len(x)):
i.upper()
print (x)
What will be the output of the following Python code?
247 4 A 1 True False None Error
print('abcd1234'.isalnum())
Select the correct output of the following String operations.
str1 = "my isname isisis jameis isis bond"
248 4 C 1 5 7 6 4
sub = "is"
print(str1.count(sub, 5))
What is the output of the following string comparison.
True True False False
249 4 print("John" > "Jhon") B 1
True False True False
print("Emma" < "Emm")
Select the correct output of the following String operations.
250 4 str1 = 'Welcome' D 1 WelcoLJIET Welcome LJIET WelcomeLJIET WelcomLJIET
print (str1[:6] + 'LJIET')
Guess the correct output of the following code?
251 4 str1 = "LJIET" A 1 JIE LJIET T LJIE LJIE JIE LJIET T LJI LJI JIE LJIET T LJIET LJIET JIE LJIET T LJIE LJI
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
Which of the following is a Python tuple?
252 4 B 1 [1, 2, 3] (1, 2, 3) {1, 2, 3} {}
Which of the following creates a tuple?
253 4 B 1 tuple1=(5)*2 tuple1=("a","b") tuple1[2]=("a","b") None of the above
What type will be printed when the following code executes?
254 4 aTuple = ("Orange") D 1 list tuple array str
print (type(aTuple))
What will the following code return?
def practice(tup):
a, b, c = tup
255 4 B 1 Orange 30 White ("Orange", 30, "White")
return b
aTuple = "Orange", 30, "White"
practice(aTuple)
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
256 4 B 1 print(t[3]) t[3] = 45 print(max(t)) print(len(t))
What will be the output of the following Python code?
257 4 t=(1,2,4,3) C 1 (1, 2) (1, 2, 4) (2, 4) (2, 4, 3)
t[1:3]
What will be the output of the following Python code?
258 4 t=(1,2,4,3) C 1 (1, 2) (1, 2, 4) (2, 4) (2, 4, 3)
t[1:-1]
What will be the output of the following Python code?
259 4 t = (4,6) A 1 (4,6, 4, 6) [4,6,4,6] (4,4,6,6) [4,4,6,6]
2*t
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
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
290 4 s = 'I love my INDIA' A 1 AomyDIAIe myINDIA AomyDIIe myINDIA AomyDIAIe myINDI AomyDAIe myINDIA
print(s[-1]+s[3:4]+s[7:9]+s[-3:-1]+s[-1:-3:-1]+s[5:9]+s[10:] )
What is the output of following python code –
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
my_tuple = (1, 2, 3, 4)
298 4 D 0.5 4 7 5 Error
my_tuple.append( (1,2,3) )
print (len(my_tuple))
def enc(st):
encoded=""
c=1
ld=st[0]
for i in range (1,len(st)):
if ld==st[i]:
c=c+1
299 4 else: B 1 A3B2A1C2A2 3A2B1A2C2A 10 Error
encoded=encoded+str(c)+ld
c=0
ld=st[i]
c=c+1
encoded=encoded+str(c)+ld
return encoded
st="AAABBACCAA"
print(enc(st))
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Example:
Input: n=12345 shift=1
325 4 Output: Result=23451 3
326 4 3
Output:
Uppercase letters : 2
Lowercase letters : 14
Digits : 3
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. Minimum 8 characters.
2. The alphabet must be between [a-z]
3. At least one alphabet should be of Upper Case [A-Z]
4. At least 1 number or digit between [0-9]
5. At least 1 character from [ _ or @ or $]
Examples:
327 4 Input: Ram@_f1234 3
Output: Valid Password
Input: Rama_fo$ab
Output: Invalid Password
Explanation: Number is missing
Input: Rama#fo9c
Output: Invalid Password
Explanation: Must consist from _ or @ or $
Write a Python program to return another string similar to the input string, but with its case inverted.
For example, input of “Mr. Ed” will result in “mR. eD” as the output string.
328 4 Note: Use of built in swapcase function is prohibited. 3
Dr. Prasad is opening a new world class hospital in a small town designed to be the first preference of the
patients in the city. Hospital has N rooms of two types – with TV and without TV, with daily rates of R1 and R2
respectively.
However, from his experience Dr. Prasad knows that the number of patients is not constant throughout the year,
instead it follows a pattern. The number of patients on any given day of the year is given by the following formula
–
(6-M)^2 + |D-15| ,
where M is the number of month (1 for jan, 2 for feb …12 for dec) and D is the date (1,2…31).
All patients prefer without TV rooms as they are cheaper, but will opt for with TV rooms only if without TV rooms
are not available. Hospital has a revenue target for the first year of operation. Given this target and the values of
N, R1 and R2 you need to identify the number of TVs the hospital should buy so that it meets the revenue target.
Assume the Hospital opens on 1st Jan and year is a non-leap year.
Constraints
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Explanation
Using the formula, the number of patients on 1st Jan will be 39, on 2nd Jan will be 38 and so on. Considering
there are only twenty rooms and rates of both type of rooms are 1500 and 1000 respectively, we will need 14 TV
sets to get revenue of 7119500. With 13 TV sets Total revenue will be less than 7000000
Example-2 :
Input
10
1000
1500
329 10000000
Output
10
Explanation
In the above example, the target will not be achieved, even by equipping all the rooms with TV. Hence, the
answer is 10 i.e. total number of rooms in the hospital.
Write a program to check if two strings are balanced. For example, strings s1 and s2 are balanced if all the
characters in the s1 are present in s2 and length of s1 & s2 should be same. The character’s position doesn’t
matter.
331 4 Example : 4
s1 = hello
s2 = olleh
Balanced
list1 = list() list1 = [] list1 = list([1, 2, 3]) All of the mentioned
332 5 Which of the following commands will create a list? D 1
333 5 What is the output when we execute list(“hello”)? A 1 [‘h’, ‘e’, ‘l’, ‘l’, ‘o’] [‘hello’] [‘llo’] [‘olleh’]
335 5 Suppose list1 is [1, 3, 2], What is list1 * 2? C 1 [2, 6, 4] [1, 3, 2, 1, 3] [1, 3, 2, 1, 3, 2] [1, 3, 2, 3, 2, 1]
What will be the output of the following Python code?
names1 = ['Amir', 'Bala', 'Chales']
if 'amir' in names1:
336 5 C 1 1 Error 2 None of the mentioned
print(1)
else:
print(2)
What will be the output of the following Python code?
list1 = [1, 2, 3, 4]
337 5 D 1 2 4 5 8
list2 = [5, 6, 7, 8]
print(len(list1 + list2))
Which of the following would give an error?
338 5 D 1 . list1=[] list1=[]*3 list1=[2,8,7] None of the above
Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
339 5 D 1 print(list1[0]) print(list1[:2]) print(list1[:-2]) All of the mentioned
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
340 5 C 1 Error None 25 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
348 5 Suppose list1 = [0.5 * x for x in range (0, 4)], list1 is: C 1 [0, 1, 2, 3] [0, 1, 2, 3, 4] [0.0, 0.5, 1.0, 1.5] [0.0, 0.5, 1.0, 1.5, 2.0]
349 5 To add a new element to a list we use which command? B 1 list1.add(5) list1.append(5) list1.addLast(5) list1.addEnd(5)
What will be the output of the following Python code?
numbers = [1, 2, 3, 4]
350 5 B 1 4 5 8 12
numbers.append([5,6,7,8])
print(len(numbers))
What will be the output of the following Python code?
a=[1,2,3]
[1,2,3,4] [1, 2, 3, 4] [1,2,3]
351 5 b=a.append(4) B 1 Syntax error
[1,2,3,4] None [1,2,3,4]
print(a)
print(b)
What is returned by the following function?
def list_transformation():
alist = [4, 2, 8, 6, 5]
Error, you cannot concatenate inside an
352 5 blist = [ ] C 1 [4, 2, 8, 6, 5] [4, 2, 8, 6, 5, 5] [9, 7, 13, 11, 10]
append.
for item in alist:
blist.append(item+5)
return blist
What will the following code print?
def mystery(num_list):
out = []
for num in num_list:
353 5 C 1 [10, 15, 20] [20, 15] [15, 20] [20, 15, 10]
if num > 10:
out.append(num)
return out
print(mystery([5, 10, 15, 20]))
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
359 5 To insert 5 to the third position in list1, we use which command? B 1 list1.insert(3, 5) list1.insert(2, 5) list1.add(3, 5) list1.append(3, 5)
What will be the output of the following Python code?
veggies = ['carrot', 'broccoli', 'potato', 'asparagus'] [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, [‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’,
360 5 A 1 [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
veggies.insert(veggies.index('broccoli'), 'celery') ‘asparagus’] ‘asparagus’] ‘asparagus’]
print(veggies)
What will be the result after the execution of above Python code?
list1=[3,2,5,7,3,6]
361 5 A 1 [3,2,5,3,6] [2,5,7,3,6] [2,5,7,6] [3,2,5,7,3,6]
list1.pop(3)
print(list1)
362 5 To remove string “hello” from list1, we use which command? A 1 list1.remove(“hello”) list1.remove(hello) list1.removeAll(“hello”) list1.removeOne(“hello”)
363 5 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()? D 1 [3, 4, 5, 20, 5, 25, 1, 3] [1, 3, 3, 4, 5, 5, 20, 25] [25, 20, 5, 5, 4, 3, 3, 1] [3, 1, 25, 5, 20, 5, 4, 3]
What will be the output of below Python code?
numbers = [1, 3, 4, 2]
364 5 A 1 [1, 2, 3, 4] [1, 3, 4] [1, 2, 3] [2, 3, 4]
numbers.sort()
print(numbers)
What will be the output of below Python code?
decimalnumber = [2.01, 2.00, 3.67, 3.28, 1.68]
365 5 D 1 [1.68, 2, 2.01, 3.28, 3.67] [1.68, 2.0, 2.01, 3, 3] [1, 2, 2, 3, 3] [1.68, 2.0, 2.01, 3.28, 3.67]
decimalnumber.sort()
print(decimalnumber)
What will be the output of below Python code?
words = ["Geeks", "For", "Geeks"]
366 5 C 1 ['Geeks','For', 'Geeks'] ['For', 'Geeks'] ['For', 'Geeks', 'Geeks'] [For, Geeks, Geeks]
words.sort()
print(words)
Tup=[2,3,4,[]]
Tup[-1].extend(range(5,35,5))
Tup[-1].append([10,20])
367 5 B 1 22 44 61 71
Tup[-1][-1].append([100,200])
print(len(Tup)+len(Tup[3])+len(Tup[-1][-1])+Tup[-1][-2])
372 5 Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use? B 1 d.size() len(d) size(d) d.len()
What will be the output of the following Python code snippet?
373 5 d = {"john":40, "peter":45} A 1 [“john”, “peter”] [“john”:40, “peter”:45] (“john”, “peter”) (“john”:40, “peter”:45)
print(list(d.keys()))
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
374 5 Which of the following is not a declaration of the dictionary? C 1 {1: ‘A’, 2: ‘B’} dict([[1,”A”],[2,”B”]]) {1,”A”,2”B”} {}
What will be the output of the following Python code?
An exception is thrown since the dictionary
375 5 a=dict() A 1 ‘‘ 1 0
is empty
a[1]
What will be the output of the following Python code?
a={ }
376 5 a[2]=1 B 1 [2,3,4] 3 2 An exception is thrown
a[1]=[2,3,4]
print(a[1][1])
389 5 Which of the following is not the correct syntax for creating a set? A 1 set([[1,2],[3,4]]) set([1,2,2,3,4]) set((1,2,3,4)) {1,2,3,4}
{}
390 5 Which of the following statements is used to create an empty set? B 1 set() [] ()
What will be the output of the following Python code?
Error as unsupported operand type for set Error as multiplication creates duplicate
391 5 s={5,6} A 1 {5,6,5,6,5,6} {5,6}
data type elements which isn’t allowed
s*3
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
395 5 Which of these about a frozenset is not true? A 1 Mutable data type Allows duplicate values Data type with unordered values Immutable data type
What will be the output of the following Python code, if s1= {1, 2, 3}?
396 5 A 1 TRUE Error No output FALSE
s1.issubset(s1)
If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the
397 5 B 1 s2.issubset(s1) s2.issuperset(s1) s1.issuperset(s2) s1.isset(s2)
function:
What will be the output of the following Python code?
x = {"apple", "banana", "cherry"}
398 5 y = {"google", "microsoft", "apple"} C 1 { 'microsoft', 'google', 'apple', 'cherry'} {'banana', 'microsoft', 'google', 'apple'} {'banana', 'microsoft', 'google', 'apple', 'cherry'} {'banana', 'microsoft', 'google', 'apple'}
z = x.union(y)
print(z)
What will be the output of the following Python code?
s1 = {1, 2, 3}
399 5 C 1 {2} {1, 2, 3} {2, 3} {3}
s2 = {2, 3}
print(s1.intersection(s2))
What will be the output of the following Python code?
x = {"apple", "banana", "cherry"}
400 5 y = {"google", "microsoft", "apple"} D 1 {"apple", "banana", "cherry"} {"google", "microsoft", "apple"} {"google", "microsoft",} {'banana', 'cherry'}
z = x.difference(y)
print(z)
What will be the output of the following Python code?
x = {"apple", "banana", "cherry"}
401 5 y = {"google", "microsoft", "apple"} B 1 {"apple", "banana", "cherry"} {'google', 'banana', 'microsoft', 'cherry'} {"google", "microsoft",} {'banana', 'cherry'}
z = x.symmetric_difference(y)
print(z)
What will be the output of the following Python code?
fruits = {"apple", "banana", "cherry"}
402 5 C 1 {'google', 'banana', 'microsoft', 'cherry'} {'banana', 'cherry'} {'banana', 'apple', 'cherry'} {"google", "microsoft", "apple"}
x = fruits.copy()
print(x)
What will be the output of the following Python code?
s="Python Programming"
403 5 C 1 17 18 12 14
print(len(set(s)))
def current_date(**kwargs):
408 5 C 0.5 date:2-1-2023 date=2-1-2023 date 02-01-2023
for i in kwargs:
print(i)
current_date(date=2-1-2023)
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
Given a list L of size N, You need to count the number of special elements in the given list. An element is special if
removal of that element makes the list balanced.
The list will be balanced if sum of even index elements is equal to the sum of odd index elements.
Example Input
Input 1:
A = [2,1,6,4]
Input 2:
A=[5,5,2,5,8]
Example Output
Output 1:
1
411 5 Output 2: 9
2
Explanation 1 :
After deleting 1 from list : [2,6,4]
(2+4) = (6)
Hence 1 is the only special element, so count is 1.
Explanation 2 :
If we delete A[0] or A[1], list will be balanced
(5+5)=(2+8)
So A[0] and A[1] are special elements, so count is 2.
The Syracuse (also called Collatz or Hailstone) sequence is generated by starting with a natural number and repeatedly
applying the following function until reaching 1:
syr(x) = 1/2 if x is even; and
syr(x) = 3x + 1 if x is odd
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
413 5 numberGames[(1,2)] = 12 C 1 30 24 33 31
sum = 0
for k in numberGames:
sum += numberGames[k]
print (len(numberGames) + sum)
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
set1={2,3}
set2={3,2}
set3={2,1}
if(set1==set2):
print("yes")
yes
415 5 A 1 no,yes no,no yes,yes
else: no
print("no")
if(set1==set3):
print("yes")
else:
print("no")
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
426 5 A 1 11 12 13 14
dict = {1: 2, 3:4, 4:11, 5:61, 7:81}
print(dict[dict[3]])
What is the output for following code:
list1=[1,2,3,4]
427 5 D 1 4 8 6 TypeError
list2=[5,6,7,8]
print(len(list1+list2-list1+list2))
What will be the output of the following Python code?
def writer():
title = 'Sir'
name = (lambda x: title + ' ' * 2x)
428 5 A 0.5 Error Sir Arthur Sir Arthur ArthurSir ArthurSirArthurSir
return name
who = writer()
print(who('Arthur'))
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Write a Python program to print the even numbers from a given list.
445 5 4
Write a Python program to swap first and last element of the list.
448 5 4
Write a Python program to find the sum of all the elements in the list.
449 5 4
Write a Python program to calculate the sum of the positive and negative numbers of a given list of numbers using lambda
453 5 4
function.
Write a Python program to rearrange positive and negative numbers in a given array using Lambda.
454 5 4
Write a Python program to find numbers divisible by nineteen or thirteen from a list of numbers using Lambda.
455 5 4
1. Set i to 0.
2. If Li = T, the search terminates successfully; return i.
3. Increase i by 1.
456 5 3
4. If i < n, go to step 2. Otherwise, the search terminates unsuccessfully.
Input:
Enter the list of numbers: 5 4 3 2 1 10 11 2
The number to search for: 1
Output:
1 was found at index 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
Given a list of elements, write a python program to perform grouping of similar elements, as different key-value list in
dictionary. Print the dictionary sorted in descending order of frequency of the elements.
Note: To perform the sorting, use the sorted function by converting the dictionary into a list of tuples. After sorting,
convert the list of tuples back into a dictionary and print it.
Input : test_list = [4, 6, 6, 4, 2, 2, 4, 8, 5, 8]
Output : {4: [4, 4, 4], 6: [6, 6], 2: [2, 2], 8: [8, 8], 5: [5]}
Explanation : Similar items grouped together on occurrences.
457 5 3
A digital image in a computer is represented by a pixels matrix. Each image processing operation in a computer may be
observed as an operation on the image matrix. Suppose you are given an N x N 2D matrix A (in the form of a list)
representing an image. Write a Python program to rotate this image by 90 degrees (clockwise) by rotating the matrix 90
degree clockwise. Write proper code to take input of N from the user and then to take input of an N x N matrix from the
user. Rotate the matrix by 90 degree clockwise and then print the rotated matrix.
Note: You are not allowed to use an extra iterable like list, tuple, etc. to do this. You need to make changes in the given list
A itself. Your program should be able to handle any N x N matrix from N = 1 to N = 20.
458 5 9
Write a Program to Print Longest Common Prefix from a given list of strings. The longest common prefix for list of strings is
the common prefix (starting of string) between all strings. For example, in the given list [“apple”, “ape”, “zebra”], there is
no common prefix because the 2 most dissimilar strings of the list “ape” and “zebra” do not share any starting characters.
If there is no common prefix between all strings in the list than return -1.
For example,
Input list: ["lessonplan", "lesson","lees", "length"]
459 5 The longest Common Prefix is: le 3
One of the ways to encrypt a string is by rearranging its characters by certain rules, they are broken up by threes, fours or
something larger. For instance, in the case of threes, the string ‘secret message’ would be broken into three groups. The
first group is sr sg, the characters at indices 0, 3, 6, 9 and 12. The second group is eemse, the characters at indices 1, 4, 7,
10, and 13. The last group is ctea, the characters at indices 2, 5, 8, and 11. The encrypted message is sr sgeemsectea.
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
If the string ‘secret message’ would be broken into four groups. The first group is seeg, the characters at indices 0, 4, 8 and
12. The second group is etse, the characters at indices 1, 5, 9 and 13. The third group is c s, the characters at indices 2, 6
and 10. The fourth group is rma, the characters at indices 3, 7 and 11. The encrypted message is seegetsec srma.
(A). Write a program that asks the user for a string, and an integer determining whether to break things up by threes,
fours, or whatever user inputs. Encrypt the string using above method.
For example,
Input message: This is python, a programming language
Input Key: 4
Output Encrypted Message: T poaomgnghiyn gm geist,prilus h ranaa
(B). If you get a message which is encoded by the method above then, Write a decryption program for the general case.
Taking input of any encrypted string from user with key number used while breaking message apart during encryption.
For example,
Input Encrypted message: Hloe gl o sogrilw g epntstfii o yotay hee nnh aoiortiimreegehrun nhnse ne
Input Key used during encryption: 5
Output Decrypted Message: Hi hello how are you going to learn python in this semester of engineering
469 5 9
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
(C). From the output string (Output Decrypted Message) of above program (Part-B), create a Dictionary with Key as First
Character and Value as list of words Starting with that Character from above string. And print that dictionary by sorting it
based on the number of elements in a list of values in descending order.
Note: Consider capital and lower first character of words as same character in this program. For ex. ‘Hi’ and ‘hello’ both will
be considered starting from ‘h’.
For example,
Enter Decrypted Message: Hi hello how are you going to learn python in this semester of engineering
Output: {'h': ['Hi', 'hello', 'how'], 't': ['to', 'this'], 'a': ['are'], 'y': ['you'], 'g': ['going'], 'l': ['learn'], 'p': ['python'], 'i': ['in'], 's':
['semester'], 'o': ['of'], 'e': ['engineering']}
Examples:
input = [1, 2, 3]
No of unique items are: 3
input = [1, 2, 2]
461 5 No of unique items are: 2 9
input = [2, 2, 2]
No of unique items are: 3
Input: [2, 3, 5]
Duplication removal list product: 30
Input: [2, 2, 3]
Duplication removal list product: 6
Input: [1, 3, 5]
Output: 9
Input: [1, 2, 2]
Output: 3
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
PART - A
PART - B
PART - C
given input, the program must print the output as shown below -
Input – [1,2,3,4]
Output – 24 (which is 1*2*3*4)
462 5 5
PART - D
Write a Python program satisfying following conditions -
For the given input, the program must print the output as shown below -
inbuilt functions. It should return -1 if it does not find the character. For the given input, the program must print the
output as shown below -
463 5 Input : m = [2, 4, -6, -9, 11, -12, 14, -5, 17] 4
For Example:
465 5 3
Input string: “Dog the quick brown fox jumps over the lazy dog”
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Write a python Program to check entered password by user is correct or not. Entered password is correct if it has upper
character, lower character , digits (but not more than 3 digits) ,special character and length is greater than or equal to
eight and less than equal to fifteen. Get the digits from entered password and convert it in to number and then convert it
in to English Word .
Example:
case 1
pw= R@m@3fa1tu9e$
Valid Password
num= 319
466 5 three hundred and nineteen 9
case 2
pw= S@m@6a1tue$
Valid Password
num= 61
sixty-one
case 3
pw= S@m@6a26u8$
Invalid Password
Write a Python Program using function to count number of strings where the string length is 3 or more and the first and
last character are same from a given list of string.
467 5 Example : 2
Input: ['abc','xyz','aba','2112','123451','12345']
Output: 3
Given a list L of size N. You need to count the number of special elements in the given list. An element is special if removal
of that element makes the list balanced. The list will be balanced if sum of even index elements is equal to the sum of odd
elements. Also print the updated lists after removal of special elements.
Example 1:
Input:
L=[5, 5, 2, 5, 8]
468 5 9
Output:
Original List: [5, 5, 2, 5, 8]
Index to be removed is: 0
List after removing index 0 : [5, 2, 5, 8]
Write Python Program to create a dictionary with the key as the first character and value as a list of words starting with
that character.
Example:
469 5 Input: Don’t wait for your feelings to change to take the action. Take the action and your feelings will change 3
Output:
{'D': ['Don’t'], 'w': ['wait', 'will'], 'f': ['for', 'feelings', 'feelings'], 'y': ['your', 'your'], 't': ['to', 'to', 'take', 'the', 'the'], 'c':
['change', 'change'], 'a': ['action.', 'action', 'and'], 'T': ['Take']}
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
d={"student0":'Student@0',"student1":'Student@11',"student2":'Student@121',
"student3":'Student@052',"student4":'Student@01278',"student5":'Student@0125', Student6":'Student@042',
"student7":'Student@07800',"student8":'Student@012'}
Write a python program to update the password of any user given the above dictionary(d) which stores the username as
the key of the dictionary and the username's password as the value of the dictionary. print the updated dictionary and
print the username and password according to ascending order of password length of the updated dictionary.
For the password updating of that username follow some instructions.
and password then display “enter correct password and username”. if the user does not enter the correct username and
password in a given three chances then display “enter correct password and username” and “try after 24h”
new password to update the password of that username. If the user enters a new password not follow the below format,
then display “follow the password format”. if the user does not enter the password in a given format in a given three
chances, then display “follow the password format” and “try after 24h”
470 5 9
The check, of whether the new password format is correct or wrong makes the user define a function. That user define a
function to return True or False for password valid or not. That user define function return value used in this program for
new password validation.
oNew password must have the below format:
1. at least 1 number between 0 and 9
2. at least 1 upper letter (between a and z)
3. at least 1 lower letter (between A and Z)
4. at least 1 special character out of @$_
5. minimum length of the password is 8 and the maximum length is 15
6. Do not use space and other special characters. Only uses @$_
If the new password follows the format of the password in a given three chances. then print the updated dictionary and
print the username and password according to ascending order of password length of an updated dictionary. If the
dictionary is not updated then take the old dictionary
Write a Python code which will return the sum of the numbers of the list.
Return 0 for an empty list.
Except the number 13 is very unlucky, so it does not count and number that come immediately after 13 also do not count
in sum.
Example :
471 5 4
[1, 2, 3, 4] = 10
[] = 0
[1, 2, 3, 4, 13] = 10
[13, 1, 2, 3, 13] = 5
[1, 13, 2, 3, 4] = 8
Write a Python program which takes a list and returns a list with the elements "shifted left by number of positions entered
by user".
Example:
Input:
472 5 3
List: [1, 2, 3, 4, 5]
Shift: 2
Output:
[3, 4, 5, 1, 2]
The contents of names.txt is listed here:
Moana
Cinderella
Tiana
Which of the following code blocks will print all of the names in names.txt?
I. names = open("names.txt", "r")
for line in names:
473 6 B 1 I II III I & III both
print(names)
II. names = open("names.txt", "r")
for line in names:
print(line)
III. names = open("names.txt", "r")
for line in names:
print("line")
How many errors are in the code below? It should open the file in read-only mode, read each line and print each line and
then close the file.
def print_contents(file)
474 6 D 1 1 2 3 4
file_obj = open(file)
for line in "file_obj":
print(line_obj)
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
File is created if does not exist. If the file exists, file is truncated( past data is lost). Both reading and writing operation can
475 6 C 1 ’r’ ’w’ ’w+’ ’a+’
take place. What is the text file mode?
476 6 From following which statement reads some bytes from the file and returns it as a string? B 1 readlines() read() readline() readpara()
477 6 From following which statement reads all the lines from the file and returns in the form of list? A 1 readlines() read() readline() readpara()
478 6 From following which statement write a string in file? A 1 write() writeline() writelines() writepara()
479 6 From following which statement writes a list in a file? C 1 write() writeline() writelines() writepara()
What happens if no arguments are passed to the seek function?
480 6 D 1 file position is set to the start of file file position is set to the end of file file position remains unchanged error
How many functions are used in the given code below:?
fileobject=open('F1.txt','r')
str=fileobject.readline()
481 6 while str: D 1 1 2 3 5
print(str)
str=fileobject.readline()
fileobject.close()
How many errors are in the code below? It should open the file in read-only mode,
read each line and print each line and then close the file.
def print_contents(file):
482 6 D 1 0 1 2 3
file_obj = open(file)
for line in "file_obj":
print(line_obj)
Select all true statements when a file is opened using the with statement.
To read 5th line from text file, which of the following statement is true? dt=f.readline(4) dt=f.readlines() dt=f.read(5) dt=f.read(4)
484 6 B 1
print(dt[4]) print(dt[4]) print(dt[3]) print(dt[5])
What will be the output of the following code snippet?
with open("hello.txt", "w") as f:
f.write("Hello World how are you today")
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Use the following file to predict the output of the following code:
test.txt content:
aaa
bbb
ccc
ddd
eee
488 6 fff A 1 aaa bbb ccc aaa bbb ccc
ggg
Code:
f=open("test.txt","r")
print(f.readline(3))
Write a function cust_data() to ask user to enter their names and age to store data in customer.txt file.
489 6 4
Write a python program to create and read the city.txt file in one go and print the contents on the output screen.
490 6 4
Write a function count_lines() to count and display the total number of lines from the file. Consider the following lines for
the file – friends.txt.
Friends are crazy, Friends are naughty !
491 6 4
Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
We are nothing without friends, Life is not possible without friends !
Write a function display_oddLines() to display odd number lines from the text file. Consider the following lines for the file –
friends.txt.
Friends are crazy, Friends are naughty !
492 6 4
Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
We are nothing without friends, Life is not possible without friends !
Write a Python program to read a text file and do following: 1. Print no. of words 2. Print no. statements
493 6 4
Write a python program that reads a text file and changes the file by capitalizing each character of file.
494 6 3
Write a Python program to copy the contents of a file to another file.
495 6 7
Write a python program to read line by line from a given files file1 & file2 and write into file3.
496 6 4
Write python program to count the number of lines in a file.
497 6 7
Write a python program to search for a string in text files.
498 6 7
Write a “pager” program. Your solution should prompt for a filename, and display the text file 25 lines at a time, pausing
499 6 each time to ask the user to enter the word “continue”, in order to show the next 25 lines or enter the word “stop” to close 4
the file.
Using a file which consists of multiple statements, find all the words from the file that can be made from all the characters
of given user’s string.
Note: If user enters same characters multiple times in a string, then word from file will only be eligible for output if it
contains that character for same or more number of times in it. (if file have apple, greenapple and user’s string is ‘aepe’
then output will only be greenapple. apple is not eligible as it contains e for 1 time only.
For example:
If a given file is:
500 6 4
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Write a Python program to reverse the content of a one file and store it in second file and also convert content of second
file into uppercase and store it in third file and also count number of Vowels in third file and also print only 2nd line from
the content of third file.
Examples:
If data file one contains the following data:
Friends are crazy, Friends are naughty !
Friends are honest, Friends are best !
Output 1:
! tseb era sdneirF ,tsenoh era sdneirF
501 6 4
! ythguan era sdneirF ,yzarc era sdneirF
Output 2:
! TSEB ERA SDNEIRF ,TSENOH ERA SDNEIRF
! YTHGUAN ERA SDNEIRF ,YZARC ERA SDNEIRF
Output 3:
Vowels = 22
Output 4:
! YTHGUAN ERA SDNEIRF ,YZARC ERA SDNEIRF
Write a python program to extract a list of all four-letter words that start and end with the same letter from a given text
502 6 4
file.
Write a python program to read a text file “Story.txt” and print only word starting with ‘I’ in reverse order.
503 6 Example: If value in text file is : ‘INDIA IS MY COUNTRY’ 2
Output will be: ‘AIDNI SI MY COUNTRY’
Write a Python program to count words, characters and spaces from text file.
Input:
No of space: 10
No of word: 13
No of character: 64
File Filtering. write all lines of a file1, except those that start with a pound sign ( # ), the comment character for Python to
file2. And display data of file2.
Example:
Enter Something (for quit enter END):Hi Friends
Enter Something (for quit enter END):how are you all
506 6 Enter Something (for quit enter END):I am fine 4
Enter Something (for quit enter END):hope you all are fine
Enter Something (for quit enter END):END
The Line started with Capital Letters:
Hi Friends
I am fine
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
Write a program to compare two text files. If they are different, give the line and column numbers in the files where the
first difference occurs.
Example:
File 1: python1.txt
Friends are crazy, Friends are naughty !
Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
new We are nothing without friends, Life is not possible without friends !
507 6 4
File 2: python2.txt
Friends are crazy, Friends are naughty !
Friends 6re honest, Friends are best !
Friends are like keygen, friends are like license key !
new We are nothing without friends, Life is not possible without friends !
Output:
line number 2 colNo. 9
print(os.listdir("C:\.... file name")) what will be output? get the list of all files and directories in the
520 7 D 1 give error give name of removed file change directory
specified directory.
A .py file containing constants/variables, classes, functions etc. related to a particular task and can be used in other
521 7 A 1 module library classes documentation
programs is called
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
#mod1.py
def change(a):
b=[x*2 for x in a]
print(b)
#mod2.py
def change(a):
522 7 b=[x*x for x in a] C 1 [2,4,6] [2,4,6] [1,4,9] [1, 4, 9] [1, 2, 3]
print(b)
Write a python program to make a module which contain all the basic functions related to string and import that module
524 7 5
in another file and use that fuctions with string given by user.
Write a python program to create a directory and subdirectory. It should print the current working directory path
525 7 2
and list of names of files present in the given directory.
Write a python program to make a module named cal.py which contain all the basic functions related to calculator like
526 7 addition, subtraction, multiplication, and division import that module in another file and use that functions with number 3
inputs given by user.
Write a program to create a module ‘first_word.py’, which returns the first word of any string passed. Show the working of
the module, by calling the module with any suitable example.
527 7 2
Input: ‘This is Python Programming’
Output: ‘This’
Write a python program to copy content of File1 into File2 in which all lines of a file1 or remaining portion of line except
those that have hash sign (#) (means comments).
Input:
# Hello LJ
Wish you happy Republic #Day
Happy 74th Republic Day
What a #Parade at Kartavya Path
528 7 3
Very Happy after watching that parade
Output:
529 8 Which is not a feature of OOP in general definitions? D 1 Efficient Code Code reusability Modularity Duplicate data
_____ represents an entity in the real world with its identity and behaviour.
530 8 B 1 A method An object A class An operator
What will be the output of the following Python code?
class test:
def __init__(self,a="Hello World"):
self.a=a
The program has an error because The program has an error display function
531 8 C 1 Nothing is displayed “Hello World” is displayed
constructor can’t have default arguments doesn’t have parameters
def display(self):
print(self.a)
obj=test()
obj.display()
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
def __init__(self):
p <__main__.Point object> (0,0)
self.x = 0 q <__main__.Point object> (0,0)
540 8 B 1 Nothing seems to have happened with the points
self.y = 0 Nothing seems to have happened with the Nothing seems to have happened with the Nothing seems to have happened with the
points points points
p = Point()
q = Point()
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
def __init__(self):
self.x = 0
self.y = 0 <__main__.Point object> <__main__.Point object> (0,0)
541 8 C 1 <__main__.Point object> FALSE <__main__.Point object> (0,0)
p = Point() True False False
q = Point()
print(p)
print(q)
print(p is q)
Will this program will print last statement?
try:
items = ['a', 'b']
third = items[1]
This won't print
print("This won't print") got an error This won't print
542 8 C 1 got an error continuing
except Exception: continuing continuing
continuing
print("got an error")
print("continuing")
print("continuing")
Sanjeev has written a program for the file which already exists to read the content from the file. Indicate the line number if
error exists in the given below code:
a=False #Line 1
while not a: #Line 2
544 8 try: #Line 3 A 1 No error Line 1 Line 2 Line 3
f_n = input("Enter file name") #Line 4
i_f = open(f_n, 'r') #Line 5
except: #Line 6
print("Input file not found") #Line 7
What will be output of the following code?
A=25
B=40
try:
L=[]
for i in range(2):
L.append(A)
print(L[3])
L.append(C)
545 8 D 1 Write properly Not in range Both A&B SyntaxError
iff len(L)<5:
print(L)
C=34
except IndexError:
print("Not in range")
except NameError:
print("Not defined")
except SyntaxError:
print("Write properly")
How many except statements can a try-except block have?
546 8 D 1 zero one more than one more than zero
When will the else part of try-except-else be executed?
547 8 C 1 always when an exception occurs when no exception occurs when an exception occurs in to except block
When is the finally block executed? only if some condition that has been specified is
548 8 D 1 when there is no exception when there is an exception always
satisfied
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
Create a class called NumberSet that accepts 2 integers as input, and defines two instance variables: num1 and num2,
556 8 which hold each of the input integers. Then, create an instance of NumberSet where its num1 is 6 and its num2 is 10. Save 4
this instance to a variable t
Create a class called Animal that accepts two numbers as inputs and assigns them respectively to two instance variables:
arms and legs. Create an instance method called limbs that, when called, returns the total number of limbs the animal has.
557 8 To the variable name spider, assign an instance of Animal that has 4 arms and 4 legs. Call the limbs method on the spider 5
instance and save the result to the variable name spidlimbs
Write a Python program to create a Vehicle class with max_speed and mileage instance attributes.
558 8 4
Write a Python class named Student with two attributes student_name, marks. Modify the attribute values of the said
559 8 4
class and print the original and modified values of the said attributes.
Write a Python class named Student with two attributes student_id, student_name. Add a new attribute student_class.
560 8 4
Create a function to display the entire attribute and their values in Student class.
Write a Python class named Rectangle constructed by a length and width and a method which will compute the area of a
561 8 4
rectangle.
Write a Python class named Circle constructed by a radius and two methods which will compute the area and the
562 8 4
perimeter of a circle.
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
Write a python program to demonstrate the use of custom exceptions in Exception handling.
565 8 3
Write a program to build a simple Student Management System using Object Oriented Programming in Python which can
perform the following operations:
accept-This method takes details from the user like name, roll number, and marks for two different subjects.
display-This method displays the details of every student.
search-This method searches for a particular student from the list of students. This method will ask the user for roll
number and then search according to the roll number
delete-This method deletes the record of a particular student with a matching roll number.
update-This method updates the roll number of the student. This method will ask for the old roll number and new roll
number. It will replace the old roll number with a new roll number.
The following instructions need to be considered while making a program.
1.Give class name as Student
2.Include methods name as accept, display, search, delete and update. (1 mark for each correct method to be formed).
3.Also form constructor with __init__ () method (2 marks for forming constructor).
4.2 marks for correct object prepared like after deletion of one roll no of student it should update the list with new roll
no. and should display it.
The example is just for understanding but logic should be for any n number of students.For Example:
List of Students
Name : A
RollNo : 1
Marks1 : 100
Marks2 : 100
Name : B
RollNo : 2
Marks1 : 90
Marks2 : 90
566 8 9
Name : C
RollNo : 3
Marks1 : 80
Marks2 : 80
Student Found,
Name : B
RollNo : 2
Marks1 : 90
Marks2 : 90
List after deletion
Name : A
RollNo : 1
Marks1 : 100
Marks2 : 100
Name : C
RollNo : 3
Marks1 : 80
Marks2 : 80
List after updation
Name : A
RollNo : 1
Marks1 : 100
Marks2 : 100
Name : C
RollNo : 2
Marks1 : 80
Marks2 : 80
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
You own a pizzeria named Olly’s Pizzas and want to create a Python program to handle the customers and revenue. Create
the following classes with the following methods:
Class Pizza containing
1.init method: to initialize the size (small, medium, large), toppings (corn, tomato, onion, capsicum, mushroom, olives,
broccoli), cheese (mozzarella, feta, cheddar). Note: One pizza can have only one size but many toppings and cheese. (1.5
marks)
Throw custom exceptions if the selects toppings or cheese not available in lists given above. (1 mark)
2.price method: to calculate the prize of the pizza in the following way:
small = 50, medium = 100, large = 200
Each topping costs 20 rupees extra, except broccoli, olives and mushroom, which are exotic and so cost 50 rupees each.
Each type of cheese costs an extra 50 rupees. (1.5 marks)
567 8 Class Order containing 9
1.init method: to initialize the name, customerid of the customer who placed the order (0.5 marks)
2.order method: to allow the customer to select pizzas with choice of toppings and cheese (1 mark)
3.bill method: to generate details about each pizza ordered by the customer and the total cost of the order. (2 marks)
1.5 marks for creating appropriate objects of these classes and writing correct output.
Write a class called WordPlay. It should have a constructor that holds a list of words. The user of the class should pass the
list of words through constructor, which user wants to use for the class. The class should have following methods:
Make Required object for WordPlay class and test all the methods.
568 8 9
For Example:
If input list entered by user is: ['apple', 'banana', 'find', 'dictionary', 'set', 'tuple', 'list', 'malayalam', 'nayan', 'grind', 'apricot']
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Write a python program that has class store which keeps record of code and price of each product. Display a menu of all
products to the user and prompt him to enter the quantity of each item required. generate a bill and display total amount.
Sample Output:
enter no of items: 3
enter code of item: milk
enter cost of item: 30
enter code of item: apple
enter cost of item: 35
enter code of item: gems
enter cost of item: 40
Item Code Price
milk 30
apple 35
569 8 gems 40 9
Enter quantity of each item:
Enter quantity of milk : 2
Enter quantity of apple : 3
Enter quantity of gems : 4
************************Bill**********************
ITEM PRICE QUANTITY SUBTOTAL
milk 30 2 60
apple 35 3 105
gems 40 4 160
**************************************
Total= 325
Write a python program that has a class Point with attributes as the x and y co-ordinates.
1.Add a method ‘distance from origin’ to class Point which returns the distance of the given point from origin. The equation
is
2.Add a method ‘translate’ to class Point, which returns a new position of point after translation
3.Add a method ‘reflect_x’ to class Point, which returns a new point which is the reflection of the point about the x-axis.
4.Add a method ‘distance’ to return distance of the given point with respect to the other point. The formula for calculating
distance between A(x1,y1) and B(x2,y2) is
570 8 9
After creating class blueprint run the following test case -
A possible collection of classes which can be used to represent a music collection (for example, inside a music player),
focusing on how they would be related by composition. You should include classes for songs, artists, albums and playlists.
For simplicity you can assume that any song or album has a single “artist” value (which could represent more than one
person), but you should include compilation albums (which contain songs by a selection of different artists). The “artist” of
a compilation album can be a special value like “Various Artists”. You can also assume that each song is associated with a
single album, but that multiple copies of the same song (which are included in different albums) can exist.
571 8 Write a simple implementation of this model which clearly shows how the different classes are composed. Write some 9
example code to show how you would use your classes to create an album and add all its songs to a playlist. Class Album
should have a method to add track, class Artist should have methods to add album and add song, class Playlist should also
have a method to add song.
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
Stacks and Queues. Write a class SQ that defines a data structure that can behave as both a queue (FIFO) or a stack (LIFO),
There are five methods that should be implemented:
You need to create a class called Atm. It should have methods to create the pin, to change the pin, to check balance, to
withdraw money, to deposit money. Also, you need to create method called menu to choose from the above given
operations which you want to perform.
create_pin Method:
Ask user to enter the pin to create a new pin. Also ask user to initialize the balance of your account.
change_pin Method:
Pin Validation is required before changing the pin. If Pin entered is wrong then message should be displayed “Enter correct
pin”. if Pin is correct then update the Old Pin with New Pin.
check_balance Method:
Pin Validation is required for checking the balance. It should display the current balance of account.
573 8 9
withdraw Method:
Pin Validation is required before withdrawing money. It should ask user for amount to withdraw. It should also display the
insufficient fund message if withdraw amount is higher than balance else balance should be updated after withdraw.
deposit Method:
Pin Validation is required before deposit of money. It should ask user for amount to deposit. balance should be updated
after deposit.
After completion of every method it should ask for choice(menu() method) to perform new operation. If you don’t want
any operation to perform then you can choose choice of exit to come out from the program
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
def two(self):
return 'A'
578 9 B 1 AA AB BB BA
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()
print(obj1.two(),obj2.two())
What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
579 9 B 1 Multi-level inheritance Multiple inheritance Hierarchical inheritance Single-level inheritance
pass
class C(A,B):
pass
In which of the following does the CricketFan class correctly inherit from the PartyAnimal class?
581 9 B 1 from party import PartyAnimal class CricketFan(PartyAnimal) an = PartyAnimal() CricketFan = PartyAnimal()
What does single-level inheritance mean? A subclass derives from a class which in A single subclass derives from a single Multiple base classes inherit a single derived
582 9 C 1 A single superclass inherits from multiple subclasses
turn derives from another class superclass class
Inheritance follows which approach to problem solving?
583 9 B 1 Bottom -up Top-down bottom-down top-up
What will be the output of the following Python code?
class A:
def __init__(self,x):
self.x = x
def count(self,x):
self.x = self.x+1
class B(A):
def __init__(self, y=0):
584 9 A.__init__(self, 3) B 1 30 31 01 An exception in thrown
self.y = y
def count(self):
self.y += 1
def main():
obj = B()
obj.count()
print(obj.x, obj.y)
main()
The child's __init__() function overrides the inheritance of the parent's __init__() function.
585 9 A 1 TRUE FALSE CAN BE TRUE OR FALSE CAN NOT SAY
What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
test of B called test of C called Error, both the classes from which D derives
586 9 class C(A): C 1 test of B called
test of C called test of B called has same method test()
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
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
person1 = People("Sally")
person2 = People("Louise")
person1.namePrint()
main()
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
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])
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
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()
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
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?
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[2] + c[3] )
What is the output of following code?
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
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 for
681 9 the class. Instantiate the class and compare the objects using _lt_ and _gt_. 5
The following illustration creates a class called data. If no argument is passed while instantiating the class a false is
682 9 4
returned, otherwise a true is returned.
Create a 5X2 integer array from a range between 100 to 200 such that the difference between each element is 10
683 9 3
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
Following is the provided numPy array. Return array of items by taking the third column from all rows
684 9 sampleArray = numpy.array([[11 ,22, 33], [44, 55, 66], [77, 88, 99]]) 2
Return array of odd rows and even columns from below numpy array
685 9 3
sampleArray = numpy.array([[3 ,6, 9, 12], [15 ,18, 21, 24], [27 ,30, 33, 36], [39 ,42, 45, 48], [51 ,54, 57, 60]])
Sort following NumPy array
Case 1: Sort array by the second row
686 9 Case 2: Sort the array by the second column 2
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])
Print max from axis 0 and min from axis 1 from the following 2-D array.
687 9 3
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])
Write a NumPy array program to convert the values of Fahrenheit degrees into Celsius degrees. The numpy array to be
considered is [0, 12, 45.21, 34, 99.91, 32] for Fahrenheit values.
Values are stored into a NumPy array. After converting the following numpy array into Celsius, then sort the array and find
the position of 0.0 (means where 0.0 value is located i.e. it’s index)
Formula to convert value of Fahrenheit to Celsius is:
C=5*F/9 - 5*32/9
Output:
Values in Fahrenheit degrees:
688 9 3
[ 0. 12. 45.21 34. 99.91 32. ]
Values in Centigrade degrees:
[-17.77777778 -11.11111111 7.33888889 1.11111111 37.72777778
0. ]
[-17.77777778 -11.11111111 0. 1.11111111 7.33888889
37.72777778]
(array([2], dtype=int64),)
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
689 9 2
class Employee(ABC):
@abstractmethod
def receive_call(self):
pass
@abstractmethod
def end_call(self):
pass
@abstractmethod
def is_free(self):
pass
@abstractmethod
def get_rank(self):
pass
690 9 9
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
690 9 9
1.Create a constructor in all three classes (Respondent, Manager and Director) which takes the id and name as input and
initializes two additional variables, rank and free. rank should be equal to 3 for Respondent, 2 for Manager and 1 for
Director. free should be a boolean variable with value True initially. (1 mark)
2.Implement rest of the methods in all three classes in the following way: (2 marks)
a.receive_call(): prints the message, “call received by (name of the employee)” and sets the free variable to False.
b.end_call(): prints the message, “call ended” and sets the free variable to True.
c. is_free(): returns the value of the free variable
d. get_rank(): returns the value of the rank variable
3.Create a class Call, with a constructor that accepts id and name of the caller and initializes a variable called assigned to
False. (0.5 marks)
4.Create a class CallHandler, with three lists, respondents, managers and directors as class variables. (0.5 marks)
5.Create an add_employee() method in CallHandler class that allows you to add an employee (an object of
Respondent/Manager/Director) into one of the above lists according to their rank. (1 mark)
6.Create a dispatch_call() method in CallHandler class that takes a call object as a parameter. This method should find the
first available employee starting from rank 3, then rank 2 and then rank 1. If a free employee is found, call its receive_call()
function and change the call’s assigned variable value to True. If no free employee is found, print the message: “Sorry! All
employees are currently busy.” (2 marks)
7.Create 3 Respondent objects, 2 Manager objects and 1 Director object and add them into the list of available employees
using the CallHandler’s add_employee() method. (1 mark)
8.Create a Call object and demonstrate how it is assigned to an employee. (1 mark)
Write a python program to create a Bus child class that inherits from the Vehicle class.
In Vehicle class vehicle name, mileage and seatingcapacity as its data member. The default fare charge of any vehicle is
seating capacity * 100. If Vehicle is Bus instance, we need to add an extra 10% on full fare as a maintenance charge. So
total fare for bus instance will become the final amount = total fare + 10% of the total fare.
The car seating capacity is 5. so, the final fare amount should be 500.
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.
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
class A: pass
class B: pass
class C: pass
695 9 class D:pass 2
class E:pass
class K1(C,A,B): pass
class K3(A,D): pass
class K2(B,D,E): pass
class Z( K1,K3,K2): pass
Write a Python Program to Find the Net Salary of Employee using Inheritance.
Create three Class Employee, Perks, NetSalary. Make an Employee class as an abstract class.
Employee class should have methods for following tasks.
- To get employee details like employee id, name and salary from user.
- To print the Employee details.
- return Salary.
- An abstract method emp_id.
Perks class should have methods for following tasks.
- To calculate DA, HRA, PF.
- To print the individual and total of Perks (DA+HRA-PF).
Netsalary class should have methods for following tasks.
- Calculate the total Salary after Perks.
696 9 - Print employee detail also prints DA, HRA, PF and net salary. 9
Sr. mar
unit_number question_text MCQ Answer option A option B option C option D
No. ks
The following given program lines will give which type of input? (Rest else lines are errorless)
A horizontal bar chart with grids and grey A horizontal bar chart without grids and grey A vertical bar chart without grids and green
706 10 plt.barh(names,values,color=”grey”) A 1 A vertical bar chart with grids and grey color
color color color
plt.grid(True)
The following syntax will create:
707 10 plt.subplot(2,1,1) A 1 Will create two subplots- above and below Will create two different line plots Will create two subplots (side by side) Syntax error will be generated
plt.subplot(2,1,2)
The following syntax indicates: position of 1st plot at 3rd row, 1st column position of 1st plot at 1st row, 3rd column, and 2nd position of 1st plot at 2nd row, 3rd column and position of 1st plot at 2nd row, 1st column
708 10 A 1
plt.subplot(3,1,2) and 2nd place place 1st place and 3rd place
For the given below figure identify the correct sequence:
Engineering $1.35
711 10 Manufacturing $3.60 3
Sales $2.25
Profit $1.80
Create a pie chart will show the cost breakdown as different sized pieces.
Here is how many students got each grade in the recent test:
712 10 A- 4, B-12, C-10, D-2. Plot a pie chart for the student grades in the recent chart with different colors for each student 3
grades and create a wedge for D. Also put a chart title as student's grade history.
Imagine you survey your friends to find the kind of movie they like best: Comedy- 4, Action -5, Romance - 6, Drama -1, SciFi
- 4. Plot a pie chart for the above survey and use different color for each analysis and create a wedge for action movies.
713 10 Also put as chart title as "Survey analysis of movie" 3
Create a Pie Chart using Python Program for the popularity data of different programming languages and displayed it as a
pie chart using the Matplotlib Python library. For Python- 29, Java – 19, Javascript – 8, C# - 7, PHP – 6, C,C++ - 5, R – 3.
714 10 3
Create an exploded view of python and show the % of each programming language in Pie Chart.
Write a python program to create a bar plot of course v/s no. of students using the following dictionary with appropriate
715 10 labels for X and Y axes and colour of the bars green. 3
Data={‘C’:20,’C++’:15,’Java’:30,’Python’:35}
Create a bar chart for the following dataset:
Country = ['USA','Canada','Germany','UK','France']
716 10 GDP_Per_Capita = [45000,42000,52000,49000,47000]. Also plot title, X-Axis, Y-Axis, different color for each country and 3
the grid should be visible
A Bar Chart to display employee id numbers on X-axis and their salaries as Y-axis in the form of a bar graph for two
departments of a company. There are two departments like sales department and purchase department. For sales
department their id's and salaries are mentioned as : x= [1001,1003,1006,1007,1009,1011] and y= [10000,
23000.50,18000.33,16500.5,12000.75, 9999.99] and for purchase department their id's and salaries are mentioned as:
717 10 5
x=[100̣2,1004,1010,1008,1014,1015] and y=[ 5000,6000,4500.5,12000,9000,10000]. Make the chart title as "Microsoft
Inc.", x-axis as emplyee id and Y axis as Salary. Use different colors for sales and purchase department.
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
Write a program to build two bar graphs using subplot function for given two dictionaries in which one graph is in 1st row
and another in second row which is horizontal representation of bar graph.
D1={“aryan”:66,”bob”:70,”jack”:66,”seema”:34}
718 10 5
D2={“joy”:45,”sid”:85,”hina”:90}
And also make a title of graph at top as “BAR PLOT”.
A program to display a histogram showing the number of employees in specific age groups. The data is shown:
emp_ages=[22,45,30,59,58,56,57,45,43,43,50,40,34,33,25,19] and their bins are [0,10,20,30,40,50,60]. Create a histogram
719 10 with x-axis label as "emplyee ages" and y axis label as " no. of employees". Create a title of the plot as "Oracle Corp". Also 3
teh color of histogram created should be cyan.
Jeff is a branch manager at a local bank. Recently Jeff’s is receiving customer feedback saying that the wait times for a
client to be served by a customer service representative are too long. Jeff decides to observe and write down the time
spent by each customer on waiting. Here are his findings from observing and writing down the wait times spent by 20
720 10 customers (in seconds): 43.1, 35.6, 5
37.6,36.5,45.3,43.5,40.3,50.2,47.3,31.2,42.2,45.5,30.3,31.4,35.6,45.2,54.1,45.6,36.5,43.1.
Plot a histogram for the above data.
Uncle Bruno owns a garden with 30 black cherry trees. Each tree is of a different height. The height of the trees (in inches):
61, 63, 64, 66, 68, 69, 71, 71.5, 72, 72.5, 73, 73.5, 74, 74.5, 76, 76.2, 76.5, 77, 77.5, 78, 78.5, 79, 79.2, 80, 81, 82, 83, 84, 85,
721 10 87. Plot a histogram with color green, title of the chart should be height of trees along with it’s fontsize as 20. 3
A Program to create a line graph to show the profits of a company in various years. The data is as mentioned: x axis as
years and y axis as profits (in Millions). X=[2012,2013,2014,2015,2016,2017] and y = [9,10,10.5,8.8,10.9,9.75]. Plot a line
722 10 3
chart with x axis as "Years" and y axis as "Profits (in Millions)" and title of the line chart as "XYZ Company". Also the
linestyle should be dashed one.
Laurell had visited a zoo recently and had collected the following data. How can Laurell use a scatter plot to represent this
723 10 data? .Take Type of Animal as X-axis and no. in Y axis. The data is as follows: Zebra-25, Lions- 5, Monkeys- 50, Elephants - 3
10, Ostriches - 20
Prayatna sells designer bags and wallets. During the sales season, he gave discounts ranging from 10% to 50% over a
period of 5 weeks. He recorded his sales for each type of discount in an array. Draw a scatter plot to show a relationship
724 10 3
between the discount offered and sales made. Take 5 sales in Rupees as user defined values
Plot a subplot showing the marks of 5 students for 6 subjects (Digital Electronics, Probability and Stochastics, Python, Full
Stack Development, IELTS (Reading), and Data Structure). All the marks for each subject and for each student is to be taken
725 10 5
user defined. Subplot should be prepared for each subject. Each Subplot should have a title of subject along with a main
title of a plot.
Write a Python program to draw a scatter plot comparing two subject marks of Mathematics and Science. Use marks of 10
students.
Test Data:
726 10 math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34] 4
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Add appropriate labels, title and legend.
Draw multiple plots in one figure using subplot function. The multiple plots include below according to order:
1. Plot a scatter plot with following data:
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
The x axis represents the age of car while y axis represents the speed of car.
The title of the graph should be age v/s speed of car. Also in graph there should be x and y labels. The marker used should
be star. The marker color should be green. The marker size should be 60.
2. Plot a horizontal bar with following data:
x=["A", "B", "C", "D"]
y=[3, 8, 1, 10]
The x axis represents the name of car while y axis represents the selling of car.
The title of the graph should be name v/s selling of car. Also in graph there should be x and y label. The horizontal bar
chart's height should be 0.1. The color of bar should be yellow.
727 10 3. Plot a histogram with following data: 9
data=[1,3,3,3,3,9,9,5,4,4,8,8,8,6,7]
bins=4, the title of the graph should be histogram of cars. The orientation should be vertical. The color of plot should be
violet
4. Plot a pie with following data:
y=[35,25,25,15]
mylabels=['Apple','Bananas','Cherries','Dates']
The title of the graph should be pie chart. The exploded view should be shown with 0.2 value for 'Apple'
Also need to provide a superior title to the subplot prepared i.e 'My Subplot for cars'(0.5 marks) and subplot preparation
(0.5 mark)
For clear visualization can use the following syntax after importing matplotlib
plt.figure(figsize=(10,10))
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
(ii). Add two new batsmen’s scores in respective 5 T20 Matches in the array created in task (i) above and print the array.
Batsman_6= [77, 83, 98, 95, 89]
Batsman_7= [92, 71, 52, 61, 53]
(iii). Add extra column with sum of all 5 T20 Matches’ scores of each batsman in the array created in task (ii) and print the
final array.
Note: Use Numpy module for all the Arrays given above.
728 10 9
Using the final array created in task(iii) above, generate graphs mentioned below:
(a). Make a line chart of Total Scores of each batsman which is stored in last column of final array v/s No. of Batsman. Use
dashed line in graph, with black color. Give label on x-axis as “No. of Batsman” and label on y-axis as “Scores”. Give title to
the chart as “Leader Board” with bold fonts.
(b). Make one Bar chart of scores of Batsman_1 and Batsman_2 for all 5 T20 matches. Give color for bars of Batsman_1 as
Purple and for Batsman_2 Dark red. Also show required legend in bar chart.
(c). Make a pie chart of Total Scores of each batsman which is stored in last column of final array. Show the pie chart with
exploded view of all pieces with 0.1 amount. Also display percentage in the pie chart. Also show required legend for pie
chart.
Note: Passing the values using numpy Array Slicing from array created in task(iii) for creating graphs above is compulsory.
Write a program to build 6 graphs(3 row and 2 column) using subplot function for given data:
Subplot 1:
Draw a line from (5,5) to (10,17) to (25,25) to (60,40) to (80,30) with suitable label in the x axis, y axis and a title.
Line color should be green.
Line style should be dotted.
Marker should be diamond.
Subplot 2:
Write a Python program to create bar plot of scores by group and gender. Give suitable label in the x axis, y axis and a title.
Colors of all label should be black and title should be bold. Color of bar plot of men and women scores should be green and
red.
Data:
Scores_men = (22, 30, 35, 35, 26)
Scores_women = (25, 32, 30, 35, 29)
Subplot 3:
Write a Python programming to create a pie chart with a title of the popularity of Car company. Make multiple wedges of
the pie. Also show the percentage.
data:
Car : Maruti Suzuki, Hyundai, Kia, Toyota, Honda
Popularity: 25,50,30,20,35
729 10 9
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. 10 ks
9
729
Subplot 4:
Write a Python program to draw a scatter plot comparing two subject marks of Mathematics and Science. Use marks of 10
students. Marker of mathematics and science should be circle and star. Colors of marker of mathematics and science
should be yellow and blue.
Test Data:
math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
Subplot 5:
Write a Python programming to display a horizontal bar chart of the popularity of programming Languages. Colors of all
programming Languages should be different. Give suitable label in the x axis, y axis and a title.
data:
Programming languages: Java, Python, PHP, JavaScript, C, C++
Popularity: 20,100,25,30,45,50
Subplot 6:
Write a Python programming to display a Histogram chart for given data.
Color of chart should be red.
Data=[10,20,20,30,30,30,40,40,40,40,50,50,50,60,60,70]
730 10
Get total profit of all months and show line plot with the following Style properties:
•Line Style dotted and Line-color should be red
•Show legend at the lower right location.
•X label name = Month Number
•Y label name = Total Profits
•Add a circle marker
•Line marker color as blue
•Line marker size as 5
•Line width should be 3
731 10 9
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
731 10 9
1. Find the maximum score in T_20-3 and print it (use only the numpy module)
2. Find the minimum score of YUVRAJ and print it (use only the numpy module)
3. Add an extra column with the sum of all 4 T20 Matches’ scores of each batsman in the array created and print it. (use
only the numpy module)
Write a NumPy program to swap columns in a given array.
Take number of rows, number of columns, and also take the values of each rows and columns as input and also number of
columns to be swapped.
Enter the number of rows: 3
Enter the number of columns: 4
Enter values for row 1: 0 1 2 3
Enter values for row 2: 4 5 6 7
Enter values for row 3: 8 9 10 11
Enter the index of the first column to be swapped: 0
Enter the index of the second column to be swapped: 1
732 10 3
Original array:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
Calculate the weekly average workout duration and calories burned. Use a loop to compute these averages for each week.
Create Visualizations:
Subplot 1 (Line plot for daily workout durations): (Days v/s Duration (in Minutes)
Subplot 2 (Line plot for weekly averages of workout duration and weekly calories burned):
Use a green line with circular markers (marker size 8) for workout duration.
Use an orange line with square markers (marker size 8) for calories burned.
Title: "Weekly Averages"
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
Subplot 5 (Pie chart for calories burned distribution over the weeks):
startangle should be 90 degree and also display percentage in pie chart with 1 digits after one decimal place.
Also display labels
Title: "Calories Burned Distribution (Pie Chart)"
The rate of change in workout durations can be calculated using the formula:
Let's consider an example to illustrate this. Suppose we have the following workout duration data for four consecutive
days:
Workout Duration already given in list above at top (workout_durations_data):
Day 1: Workout Duration = 40 minutes
Day 2: Workout Duration = 50 minutes
Day 3: Workout Duration = 45 minutes
Day 4: Workout Duration = 55 minutes
We want to calculate the rate of change in workout durations for each day.
The negative rate of change between Day 2 and Day 3 indicates a decrease in workout duration, while the positive rate of
change between Day 3 and Day 4 indicates an increase.
In the context of the fitness data visualization, the rate of change plot will show how the workout durations are changing
on a daily basis, providing insights into trends and fluctuations in the individual's exercise routine.
Instructions:
Implement the required calculations using nested loops.
Ensure that each subplot is labeled appropriately.
Customize the visualizations with specific colors, markers, and marker sizes.
Display the main title for the entire figure.