CS QB 2025 - YK-Opt
CS QB 2025 - YK-Opt
COMPUTER SCIENCE
– CLASS XII
Revise your concepts topic-wise in different
question formats to strengthen your concepts
and score excellent marks in board exams.
- Yogesh Kumar
QB/XII/CS-083/2025/YK/Initial Pages
© Author
No part of this Question Bank can be reproduced in any form (print, electronic, or any other)
without prior written permission from the author.
All suggestions for the improvement in this question bank are most welcome. Suggestions
can be emailed to [email protected]
Utmost care has been taken to ensure that there are no mistakes (printing or other) in the
book. But human errors cannot be 100% ruled out. If you find any mistake in the book, please
report it at [email protected] .
Contents
1. Syllabus
2. Syllabus Coverage Checklist
3. Questions
(I) Python
1. MCQs
(i) Basics-1 Q1
(ii) Basics-2 Q5
(iii) Boolean Expressions Q8
(iv) range() and random Q13
(v) Lists Q16
(vi) Tuples Q21
(vii) Strings Q23
(viii) Dictionaries Q25
(ix) Functions Q27
(x) Text Files Q30
(xi) CSV Files Q36
(xii) Binary Files Q39
(xiii)Exception Handling Q42
2. Assertion Reasoning Q44
3. Finding Output
(i) Compound Assignment Operators Q47
(ii) if..elif..else Q49
(iii) Loops Q55
(iv) Lists Q58
(v) Tuples Q62
(vi) Strings Q64
(vii) Dictionaries Q69
(viii)Functions Q73
4. Correcting the code Q76
5. Writing Single-statement code Q81
6. Writing Functions Q84
7. Text File Operations Q86
8. CSV File Operations Q89
9. Binary File Operations Q92
10. Stacks Q94
(II) Database Management
1. MCQs Q98
2. Assertion Reasoning Q108
3. Descriptive Questions Q111
4. Writing Queries Q113
5. Writing Queries and Finding Output Q115
6. Python - Database Connectivity Q130
4. Answers
(I) Python
1. MCQs A1
2. Assertion Reasoning A2
3. Finding Output A5
4. Correcting the code A5
5. Writing Single-statement code A10
6. Writing Functions A12
7. Text File Operations A15
8. CSV File Operations A19
9. Binary File Operations A21
10. Stacks A27
(II) Database Management
1. MCQs A30
2. Assertion Reasoning A30
3. Descriptive Questions A30
4. Writing Queries A31
5. Writing Queries and Finding Output A33
6. Python - Database Connectivity A41
(III) Computer Networks
4. MCQs A44
5. Descriptive Questions A44
6. Case Studies A48
13. Functions:
a. types of function (built-in functions, functions defined in module, user defined functions)
b. creating user defined function
c. arguments and parameters: default parameters, positional parameters
d. function returning value(s), flow of execution
e. scope of a variable (global scope, local scope)
14. Exception Handling: Introduction, handling exceptions using try-except-finally blocks
15. Introduction to files, types of files (Text file, Binary file, CSV file), relative and absolute paths
16. Text file:
a. opening a text file, text file open modes (r, r+, w, w+, a, a+), closing a text file, opening a file
using with clause
b. writing/appending data to a text file using write() and writelines()
c. reading from a text file using read(), readline() and readlines()
d. seek and tell methods
e. manipulation of data in a text file
17. Binary file:
a. basic operations on a binary file: open using file open modes (rb, rb+, wb, wb+, ab, ab+), close
a binary file,
b. import pickle module, dump() and load() method
c. read, write/create, search, append and update operations in a binary file
18. CSV file:
a. import csv module, open / close csv file,
b. write into a csv file using writer(), writerow(), writerows()
c. read from a csv file using reader()
19. Data Structure: Stack, operations on stack (push & pop), implementation of stack using list.
(I) Python
Python MCQs
Basics-1
1. Who developed Python?
a) Guido Van Rossum b) Bill gates
c) Charles Babbage d) Steve Jobs
3. Python is
a) case-sensitive b) not case-sensitive
c) selectively case-sensitive d) none of these
For tutorial on Floor Division (//) and Remainder(%) operators, scan the QR code:
√𝑥−𝑦
a) (x+y)**1/3/x**1/3-y b) (x+y)**(1/3)/x**(1/3)-y
c) (x+y)**1/3/x**(1/3)-y d) (x+y)**(1/3)/(x**(1/3)-y)
Python MCQs
Basics-2
1. Which of the following is an invalid variable name?
a) My Book b) MyBook
c) myBook d) mY_BooK
8. What will be the values of a and b after execution of the following statement:
a,b=10
a) a=10 and b=10 b) a=10 and b=0
c) a=0 and b=10 d) The given statement is incorrect
9. What will be the values of a and b after execution of the following statement:
a,b=10,20
a) a=10 and b=10 b) a=20 and b=20
c) a=10 and b=20 d) The given statement is incorrect
10. What will be the values of a and b after execution of the following code segment:
a,b=10,20
a+=b
b+=a
a) a=10 and b=10 b) a=30 and b=20
c) a=30 and b=30 d) a=30 and b=50
11. What will be the values of a and b after execution of the following code segment:
a,b=10,20
a=+b
b+=a
a) a=20 and b=20 b) a=20 and b=40
c) a=40 and b=20 d) The given code has an error
www.yogeshsir.com Page: Q6/150 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Questions
12. What will be the values of a and b after execution of the following code segment:
a,b=5,15
a+=b
b=a-b
a-=b
a) a=5 and b=15 b) a=15 and b=5
c) a=10 and b=-10 d) The given code has an error
13. What will be the values of a and b after execution of the following code segment:
a,b=5,15
a+=a+b
b-=a-b
a) a=25 and b=5 b) a=5 and b=25
c) a=20 and b=-10 d) a=20 and b=10
14. What will be the values of a and b after execution of the following code segment:
a,b=1,2
a*=a+b
b//=a-b
a) a=2 and b=3 b) a=2 and b=2
c) a=3 and b=3 d) a=3 and b=2
Python MCQs
Boolean Expressions
1. Which of the following expressions is True?
a) 2>3 b) 3<4
c) 3!=3 d) 3>3
33. Which of the following expression checks the condition: num1 is equal to num2
a) num1=num2 b) num1==num2
c) num1<=num2 d) num1>=num2
34. Which of the following expression checks the condition: num1 is a factor of num2
a) num1/num2==0 b) num1//num2==0
c) num1%num2==0 d) num2%num1==0
35. Which of the following expression checks the condition: num1 is a multiple of num2
a) num1/num2==0 b) num1//num2==0
c) num1%num2==0 d) num2%num1==0
36. Which of the following expression checks the condition: num1 is a multiple of 3 or 5
a) num1%3 or 5==0 b) num1%3 or num1%5==0
c) num1%3==0 or num1%5==0 d) num1%15==0
37. Which of the following expression checks the condition: ch (an integer) is a digit
a) ch>='0' and ch<='9' b) '0'<=ch<='9'
c) 0<=ch<=9 d) ch>=0<=9
38. Which of the following expression checks the condition: ch (a single character string) is a digit?
a) ch>='0' or ch<='9' b) ch>=0 or ch<=9
c) ch>='0' and ch<='9' d) ch>=0 and ch<=9
Python MCQs
range() and random
1. Which sequence of values will be generated by the function call range(5)?
a) 1,2,3,4,5 b) 0,1,2,3,4,5
c) 0,1,2,3,4 d) 1,2,3,4
7. Which of the following functions from random module generate floating point random numbers?
(Select two correct options)
a) random() b) randint()
c) uniform() d) randrange()
8. Which of the following function from random module does not take any argument?
a) random() b) randint()
c) uniform() d) randrange()
9. Which of the following function from random module accept exactly two arguments? (Select two
correct options)
a) random() b) randint()
c) uniform() d) randrange()
10. What is the minimum and maximum number of arguments accepted by randrange() function of
random module?
a) 0,2 b) 1,2
c) 0,3 d) 1,3
11. Which function of random module always generates a random number less than 1?
a) random() b) randint()
c) uniform() d) randrange()
12. Identify the number which cannot be generated with the following code:
random.random()
a) 1 b) 0
c) 0.9643 d) 0.0012
13. Identify the number which cannot be generated with the following code:
random.randint(1,10)
a) 1 b) 5
c) 10 d) 1.5
14. Identify the number which cannot be generated with the following code:
random.randrange(1,10)
a) 1 b) 5
c) 10 d) 9
15. Identify the number which cannot be generated with the following code:
random.randrange(1,10,3)
a) 1 b) 3
c) 4 d) 7
17. Identify the output(s) which is/are not possible with the following code:
import random
a=random.randint(1,10); b=random.randrange(1,10)
print(a+b)
a) 1 b) 10
c) 11 d) 20
18. Identify the output(s) which is/are not possible with the following code:
import random
a=random.uniform(2,10); b=round(a,2)
print(b)
a) 1.23 b) 3.23
c) 5.31 d) 9.99
19. Identify the output(s) which is/are not possible with the following code:
import random
a=random.random()*100
b=round(a,2)
print(b)
a) 0.53 b) 1.23
c) 100.23 d) 9.99
20. Identify the output(s) which is/are not possible with the following code:
import random
a=random.uniform(3,30); b=int(a)%4; c=round(a,b)
print(c)
a) 4.5 b) 3.534
c) 24.0 d) 13.5
21. Identify the output(s) which is/are not possible with the following code:
import random
a=random.randint(1,4)
for i in range(4):
print(i%a,end="@")
a) 0@0@0@0@ b) 0@1@0@1@
c) 0@1@2@0@ d) 0@1@1@0@
22. Identify the output(s) which is/are not possible with the following code:
import random
a=random.randrange(1,6,2)
for i in range(a):
print(i+a,end="#")
a) 3#4#5# b) 1#2#
c) 5#6#7#8#9# d) 1#
23. Identify the output(s) which is/are not possible with the following code:
import random
a=random.randint(1,5); b=random.randrange(a,a+5)
for i in range(a,b):
print(i,end="#")
a) 3#4#5# b) 1#2#
c) 5#6#7#8# d) 5#6#7
24. Identify the output(s) which is/are not possible with the following code:
import random
r='random'
a=random.randrange(4)
for i in range(4):
n=abs(a-i); print(r[n],end="@")
a) r@a@n@d@ b) a@n@d@o@
c) a@r@a@n@ d) d@n@a@r@
25. Identify the output(s) which is/are not possible with the following code:
r='random'
a=random.randrange(4)
for i in range(4):
n=a-i
print(r[n],end="@")
a) r@m@o@d@ b) a@r@m@o@
c) a@r@a@n@ d) d@n@a@r@
Python MCQs
Lists
If nums=[5,3,1,8,6,7,4]
1. then what will be the value of the following expression?
len(nums)
a) 4 b) 5
c) 6 d) 7
10. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[::-3]
a) [5,8] b) [5,8,4]
c) [4,8] d) [4,8,5]
11. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[1:4]
a) [5,6] b) [5,3,1,8,6]
c) [3,1,8] d) [ ]
13. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[:1:4]
a) [ ] b) [5]
c) [3,1,8] d) [5,3,1,8,6]
14. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[3:3:3]
a) [ ] b) [3]
c) [8] d) [ 8,6,7]
15. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[1:2:3]
a) [5] b) [3]
c) [1] d) [ 3,1]
17. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-2:20:2]
a) [7,4] b) [6,4]
c) [6] d) [ 7]
18. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-2:7:2]
a) [7,4] b) [6,4]
c) [6] d) [ 7]
19. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-2:7:-2]
a) [7,8] b) [7,8,3]
c) [3,8] d) [ ]
20. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-2:-7:-2]
a) [7,8] b) [7,8,3]
c) [3,8] d) [ ]
22. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[1:-4]
a) [3,1] b) [3,1,8,6]
c) [3,1,8] d) [ ]
23. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-1:-4]
a) [5,6] b) [5,3,1,8,6]
c) [3,1,8] d) [ ]
24. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[-1::-4]
a) [7] b) [7,3]
c) [4] d) [4,1 ]
25. If nums=[5,3,1,8,6,7,4] then what will be the value of the following expression?
nums[:-1:-4]
a) [4] b) [8]
c) [4,7,6] d) [ ]
36. If A=[5,3,8] and B=[A,8,66,45], then which of the following expressions is/are True?
a) A in B b) [A] in B
c) B in A d) [B] in A
37. If A=[5,3,8] and B=[5,8,3] then which of the following expressions is/are True?
a) A == B b) A<B
c) A>B d) A<=B
38. If A=list('madhur') and B=list('Madhuri') then which of the following expressions is/are
True?
a) A < B b) A <= B
c) A > B d) A >= B
43. If A=[5,3,2,8,7,9] then which of the following statements will insert (NOT Over right) 4 at A[0]?
a) A[0] = 4 b) A[0].insert(4)
c) A.insert(0,4) d) A.insert(4,0)
44. If A=[5,3,2,8,7,9] then which of the following statements will increase the length of A?
a) A[0] = 0 b) A[0]=[0]
c) A[0]=0, d) A[:0]=0,
45. If A=[5,3,2,8,7,9] then which of the following statements will decrease the length of A?
a) A[5:] = [5,6] b) A[:5]=[5,6]
c) A[::5]=[5,6] d) A[5]=[5,6]
Python MCQs
Tuples
1. Which of the following statements will create a tuple?
a) a=1 b) a=1,
c) a=(1) d) a=tuple(1)
3. Which variable will not represent a tuple after execution of the following code snippet?
a=1,2,3,4,5,6
b=a[1],
c,d=a[2],a[3]
e=a[4],a[5]
a) a b) b
c) c d) e
To understand how += is different for lists and tuples, scan the QR code:
7. If A=1,2,3,4,5
then which of the following statements is/are valid?
a) A[1]=1 b) A+=1
c) A.pop() d) A=A[1:]
Python MCQs
Strings
1. Which of the following is/are invalid string(s) in Python?
a) string b) 'string'
c) "string" d) """string"""
5. Given s="DECEMBER 2023" then which of the following expressions will be True?
a) s.isupper() b) s.islower()
c) s.isalpha() d) s.isalnum()
13. If s='an apple' then which of the following expressions is/are invalid?
a) list(s) b) tuple(s)
c) str(s) d) None of these
17. If s='an apple' then which of the following is/are an invalid expression(s)?
a) s[0] b) s[0:]
c) s[:0] d) s[0:0:0]
18. If s='an apple' then which of the following expressions will represent an empty string?
a) s[0] b) s[0:]
c) s[:0] d) s[0:0:0]
19. If s='mathematics' then which of the following will return a list of three elements?
a) s.split() b) s.split('3')
c) s.split('e') d) s.split('m')
20. If s='mathematics' then which of the following will represent a list of two elements?
a) s.split('a',0) b) s.split('a',1)
c) s.split('a',2) d) s.split('a',3)
24. If s='mathematics' then which of the following expressions will raise an error?
a) s.find('book') b) s.index('book')
c) s.count('book') d) s.split('book')
25. If s='mathematics' then which of the following expressions will raise an error?
a) s.partition() b) s.partition('book')
c) s.split() d) s.index(s)
Python MCQs
Dictionaries
Which
1. of the following statements is/are correct?
a) Dictionaries are immutable b) A dictionary can have all keys and no
values
c) Keys of a dictionary must be of the same d) Keys of a dictionary must be of immutable
type. types.
11. If d={1:"One",2:"Two"} , then Which of the following statements will create a dictionary?
a) dict.fromkeys(d) b) dict.fromkeys(d.keys())
c) dict.fromkeys(d.values()) d) All of these
13. If d={1:"One",2:"Two"} , then Which of the following expressions will raise an exception?
a) del d[1] b) del d["Two"]
c) del d d) None of these
14. Which of the following methods will delete the last element from a dictionary?
a) pop() b) popitem()
c) remove() d) clear()
16. Which of the following methods will raise an exception if no argument is given?
a) popitem() b) clear()
c) copy() d) setdefault()
17. Which of the following dictionary methods always returns a tuple from a non-empty dictionary?
a) setdefault() b) get()
c) pop() d) popitem()
20. If d is an empty dictionary then which of the following expressions will raise an exception?
a) d.get(5) b) d.setdefault(5)
c) d.pop() d) del d
Python MCQs
Functions
1. Which keyword is used to define a function?
a) def b) define
c) func d) function
10. Which of the function calls is/are invalid for the following function:
def test(a,b=0):
print(a-b)
a) test(5) b) test(5,3)
c) test(b=5,a=3) d) test(a=4,7)
11. Which of the function calls is/are invalid for the following function:
def test(a=10,b=20):
pass
a) test(5) b) test(5,3)
c) test(b=5,a=3) d) test(a=4,7)
12. Which of the function calls is/are valid for the following function:
def test(a,b,c):
print(a+b+c)
a) test(5,c=4,6) b) test(5,b=4,6)
c) test(a=5,b=4,6) d) test(4,5,c=4)
Python MCQs
Text Files
1. A text file contains:
a) Lines of text b) Lines of formatted text
c) Only one line of text d) Text and images
8. Which of the following specify (there may be multiple correct options) read only mode for a text
file?
a) 'r' b) 'rt'
c) 'rb' d) 'r+'
9. The file opening mode 'rt' is the same as (there may be multiple correct options):
a) 'r' b) 'tr'
c) 'r+' d) 'rb'
11. What is the data type of the argument of write() method of file object?
a) int b) float
c) str d) any iterable
12. The writelines() method of file object accepts any iterable as a parameter. What should be
the data type of the elements of this iterable?
a) int b) float
c) str d) any type
13. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'w')
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
14. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'a')
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
15. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'w+')
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
16. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'a+')
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
17. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'r+')
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
18. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'a')
f.seek(0)
f.write("D")
f.close()
a) D b) Deep
c) BeepD d) DBeep
19. A text file 'sample.txt' contains the text 'Beep' only. What will be the contents of the file after
execution of the following code:
f=open("sample.txt",'r+')
f.seek(2)
f.write("D")
f.close()
a) D b) BeDp
c) BDep d) DBeep
20. If a text file 'sample.txt' contains multiple lines of text, what will be the data type of variable txt
after execution of the following code:
f=open("sample.txt",'rt')
txt = f.read()
print(txt)
a) int b) float
c) str d) list
21. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'rt')
data = f.read()
print(data)
a) first character of the file b) first word of the file
c) first line of the file d) Entire file content
22. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'rt')
data = f.read(5)
print(data)
a) 5 b) first 5 characters of the file
c) 5 character of the file
th
d) Entire file content 5 times
23. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'rt')
f.seek(5)
data = f.read(1)
print(data)
a) first 5 characters of the file b) first 6 characters of the file
c) 5th character of the file d) 6th character of the file
24. Pick the correct option to be filled in the given code so as to read data from 8th character to 20th
character from the file:
f=open("sample.txt",'rt')
f.seek(7)
data = f.read(__)
a) 12 b) 13
c) 14 d) 20
25. If a text file 'sample.txt' contains multiple lines of text, what will be the data type of variable txt
after execution of the following code:
f=open("sample.txt",'rt')
txt = f.readline()
a) int b) float
c) str d) list
26. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f =open("sample.txt",'rt')
data = f.readline()
print(data)
a) first character of the file b) first word of the file
c) first line of the file d) Entire file content
27. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'rt')
data = f.readline(50)
print(data)
a) First line of the file b) First 50 characters of the file
c) First 50 lines of the file d) First 50 characters or first line, whichever
is smaller.
28. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'rt')
for i in range(5):
f.readline()
print(f.readline())
a) first 5 lines of the file b) first 6 lines of the file
c) 5 line of the file
th
d) 6th line of the file
29. If a text file 'sample.txt' contains multiple lines of text, what will be the output of the following code:
f=open("sample.txt",'r')
for i in range(5):
print(f.readline())
a) first 5 lines of the file b) first 6 lines of the file
c) 5 line of the file
th
d) 6th line of the file
30. If a text file 'sample.txt' contains 10 lines of text, what will be the data type of variable txt after
execution of the following code:
f=open("sample.txt",'rt')
txt = f.readlines()
a) int b) float
c) str d) list
31. If a text file 'sample.txt' contains 10 lines of text, what will be the output of the following code:
f=open("sample.txt",'r')
data=f.readlines()
print(data[3])
a) 3rd character of the file b) 3rd line of the file
c) 4th character of the file d) 4th line of the file
32. If a text file 'sample.txt' contains 10 lines of text, what will be the output of the following code:
f=open("sample.txt",'r')
data=f.readlines()
print(data[-1])
a) Last character of the file b) Last line of the file
c) '\n' d) A blank line
33. If a text file 'try.txt' contains 5 lines of text & lengths of these lines are 10, 15, 10, 15, 20
respectively, what will be the output of the following code:
f=open("sample.txt",'rt')
data = f.readlines(40)
for s in data:
print(s.strip())
a) Entire file content b) First 40 characters of the file
c) First 4 lines of the file d) First 3 lines of the file
34. How many arguments does seek() accept for a text file?
a) 0 or 1 b) 1 or 2
c) Exactly 1 d) Exactly 2
35. Which of the statements is/are incorrect for the following file object:
f=open("sample.txt")
a) f.seek(5) b) f.seek(5,0)
c) f.seek(0,1) d) f.seek(5,1)
36. How many arguments does tell() accept for a text file?
a) 0 b) 1
c) 2 d) 1 or 2
37. What will be the contents of the file 'sample.txt' after execution of the following script:
f=open("sample.txt",'w')
f.write('Seven')
a) Seven b) The file will be empty as the file is not
closed
c) The code has syntax error d) The code will raise an exception.
Python MCQs
CSV Files
1. CSV stands for:
a) Comma Spaced Values b) Comma Separated Values
c) Completely Separated Values d) Common Separated Values
9. Which method of writer object allows writing of multiple records in a csv file?
a) writerow() b) writerows()
c) writeline() d) writelines()
15. The following code is inserting an unwanted blank line after every row in the file sample.csv::
import csv
with open("sample.csv",'w') as f:
w=csv.writer(f)
data=[['a','b','c'],[1,2,3]]
w.writerows(data)
To correct this, we have to:
a) close the file at the end b) use keyword argument newline='' or
newline='\n' with the open() function
c) make data a tuple instead of list d) use '\n' as the last element of each record
Python MCQs
Binary Files
What
1. kind of data can be stored in a Binary file?
a) Numbers only b) Strings only
c) lists only d) Any kind of data
5. Select the correct statement(s) in context of pickle module (There may be multiple answers):
a) load() writes data into a binary file b) dump() writes data into a binary file
c) load() reads data from a binary file d) dump() reads data from a binary file
9. Which of the following specifies the read-only mode for a binary file?
a) 'r' b) 'rb'
c) 'r+' d) 'rb+'
10. Which of the following modes will open a binary file in read-write mode without deleting the
existing file contents?
a) 'rb+' b) 'rw'
c) 'rw+' d) 'wb+'
11. Which of the following modes will create a binary file and open it in read-write mode?
a) 'rb+' b) 'rw'
c) 'rw+' d) 'wb+'
12. Which of the following commands will open the binary file "d:\emp\log\temp.dat" in read-write
mode without deleting the existing file content?
a) open("d:\emp\log\temp.dat", "rb")
b) open("d:\emp\log\temp.dat", "rw")
c) open("d:\\emp\\log\\temp.dat", "r+b")
d) open("d:\\emp\\log\\temp.dat", "rw+")
13. Which of the following commands will open the binary file "d:\emp\log\temp.dat" in read-only
mode?
a) open(r"d:\emp\log\temp.dat", "rb")
b) open(r"d:\emp\log\temp.dat", "rw")
c) open(r"d:\\emp\\log\\temp.dat", "rb+")
d) open("d:\\emp\\log\\temp.dat", "rw+")
14. Which of the following commands will raise an exception if the binary file "books.dat" does not
exist?
a) open("books.dat","rb") b) open("books.dat",'ab')
c) open("books.dat",'wb') d) open("books.dat",'w')
15. Pick the statement which correctly differentiates between 'wb+' and 'ab+' modes of opening an
already existing binary file:
a) 'wb+' deletes the existing data from the b) 'wb+' does not delete the existing data
file whereas 'ab+' does not delete. from the file whereas 'ab+' deletes.
c) 'wb+' will raise an exception because the d) There is no difference
file already exists whereas 'ab+' will not
raise any exception.
16. Pick the statement which correctly differentiates between 'rb' and 'rb+' modes of opening an
already existing binary file:
a) In 'rb' mode we can read only one record b) In 'rb' mode we can only read data from
at a time, whereas in 'rb+' we can read the file, whereas in 'rb+' we can read as
multiple records at a time. well as write data in the file.
c) In 'rb' mode the file pointer starts at 0, d) 'rb' mode does not allow seek(),
whereas in 'rb+' the file pointer starts whereas 'rb+' allows seek() on the
from the end of the file. file.
17. Select the correct statement to write a list, named Data, into a binary file represented by file object
outfile.
a) pickle.write(Data,outfile) b) pickle.write(outfile,Data)
c) pickle.dump(Data,outfile) d) pickle.dump(outfile,Data)
22. If f is the file object representing a binary file opened in 'rb' mode, which of the following
statements will set the file pointer to the end of the file?
a) f.seek(-1) b) f.seek(0,0)
c) f.seek(0,1) d) f.seek(0,2)
23. If f is the file object representing a binary file opened in 'rb+' mode, then which of the following
statements will set the file pointer to 12 bytes before the current position?
a) f.seek(-12) b) f.seek(-12,0)
c) f.seek(-12,1) d) f.seek(-12,2)
24. If f is the file object representing a binary file opened in 'wb' mode, then which of the following
statements will set the file pointer to 12 (There may be multiple answers)?
a) f.seek(12) b) f.seek(12,0)
c) f.seek(12,1) d) f.seek(12,2)
25. If f is the file object representing a binary file opened in 'ab+' mode, which of the following
statements is/are correct in this context?
a) seek() method will raise an exception b) new data will be written at the end of the
file irrespective of the current value of file
pointer.
c) seek() method can be invoked only with d) None of the above
one argument.
Python MCQs
Exception Handling
1. In Python, an exception is a:
a) syntax error b) run-time error
c) logical error d) break statement in a loop
2. An exception causes:
a) abnormal termination of the script b) an infinite loop
c) an incorrect result d) closing of the IDE
8. What exception will be raised if user enters 1.2 in response to the following statement:
a=int(input("Enter an integer: "))
a) NameError b) TypeError
c) ValueError d) DomainError
10. What exception will be raised if a script tries to read data from a binary file beyond the end of file?
a) FileError b) EOFError
c) ReadError d) BEOFError
14. Which of the following statements will not raise any exception?
a) a=3/(6-6) b) a=2,3
c) a='3'%'2' d) a=eval(2+3)
42. Assertion (A): If the arguments in a function call statement match the number and order of arguments as
defined in the function definition, such arguments are called positional arguments.
Reasoning (R): In a function call, keyword argument(s) are followed by positional argument(s).
43. Assertion (A): In Python, the statement return [<expression>] exits a function.
Reasoning (R): return statement transfers the control to the caller. A return statement with no arguments is
the same as return None.
44. Assertion (A):- keyword arguments are related to the function calls.
Reasoning (R):- when you use keyword arguments in a function call, the caller identifies the arguments by
parameter name.
45. Assertion (A): The default value of an argument will be used inside a function if we do not pass a value to
that argument at the time of the function call.
Reasoning (R): the default arguments are optional during the function call.
46. Assertion (A): Built in functions are predefined in the language that are used directly.
Reasoning(R): print() and input() are built in functions in Python.
47. Assertion (A):- The default arguments can be skipped in the function call.
Reasoning (R):- The default argument will take the default values even if the values are supplied in the
function call.
48. Assertion (A): The function definition def calculate(a, b,c=1,d): will give error.
Reasoning (R): All the non-default arguments must precede the default arguments.
49. Assertion (A): A function in Python always returns a value.
Reasoning (R): return statement is optional in Python.
50. Assertion (A): We cannot redefine an inbuilt function in Python.
Reasoning (R): Keywords cannot be redefined in Python.
51. Assertion (A): If a text file already containing some text is opened in write mode the previous contents are
overwritten.
Reasoning (R): When a file is opened in write mode the initial value of file pointer is 0.
52. Assertion (A): If a text file is opened in 'a+' mode, then we can write the data anywhere in the file.
Reasoning (R): seek() method can be used to place the pointer anywhere in a file.
53. Assertion (A): seek() method can be used instead of tell() method.
Reasoning (R): seek(0) returns the value of file pointer without changing it.
54. Assertion (A): We can use any string, instead of a comma, as a delimiter of a csv file.
Reasoning (R): Comma is the default delimiter of a csv file.
55. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file.
Reasoning (R): In a CSV file the information is organized with one record on each line and each field is
separated by semi-colon.
56. Assertion (A): CSV module allows to write a single record in each row in a CSV file using the writerow()
function.
Reasoning (R): writerow() function creates header row in csv file by default.
57. Assertion (A): CSV stands for Comma Separated Values.
Reasoning (R): CSV files are a common file format for transferring and storing data.
58. Assertion (A): Pickling is the process by which a Python object is converted to a byte stream.
Reasoning (R): load() method is used to write the objects in a binary file. dump() method is used to read
data from a binary file.
59. Assertion (A): If only strings are written to a binary file, then it can be treated as a text file.
Reasoning (R): Pickling and unpickling can be done for strings also.
60. Assertion (A): A binary file in python can be used to store any kind of objects that can be later retrieved in
their original form using pickle module.
Reasoning (R): Binary files are just like normal text files and can be read using a text editor like notepad.
10. What will be the output after execution of the following code:
a,b,c=5,10,15
b+=a+b+c
c+=a+b+c
a+=a+b+c
print(a,b,c)
11. What will be the output after execution of the following code:
a,b,c=5,10,15
c+=a+b+c
a+=a+b+c
b+=a+b+c
print(a,b,c)
12. What will be the output after execution of the following code:
a,b,c=1,2,3
a*=a+b
b*=a+b
c*=a+b
print(a,b,c)
13. What will be the output after execution of the following code:
a,b,c=1,2,3
b*=a+b
c+=a+b
a=+b*c
print(a,b,c)
14. What will be the output after execution of the following code:
a,b,c=10,7,5
b//=b//c
a%=a%b
c*=c*a
print(a,b,c)
15. What will be the output after execution of the following code:
a,b,c=10,7,5
a%=4
b%=a
c%=b
print(a,b,c)
2. Find error(s), if any, in each of the following function calls, and rewrite the correct function call
underlining the corrections made:
(i) input(Enter a number: ) (ii) input("Enter your age: ") (iii) int(56)
(iv) int("56.6") (v) int("fifty6") (vi) int('5six') (vii) int(5six)
(viii) float(12.3) (ix) float("-12.45") (x) float(5) (xi) int(5/4)
(xii) float("5/4") (xiii) eval('10+2') (xiv) eval('10') (xv) eval(10)
(xvi) eval(10*2) (xvii) int(eval("10/3")) (xviii) eval(int(10/3))
(xix) eval(int("10/3")) (xx) eval(float("10/3"))
3. Find error(s), if any, in each of the following scripts, and rewrite the correct code underlining the
corrections made:
(i) n1,n2=5,4
if n1=n2:
print("Equal")
(ii) n1=n2=12/5
if n1!=n2
print"Not equal"
else print"Equal"
(iii) 12=age
if age=<10:
print(Primary)
elseif age=<13:
print(Middle)
elseif age<=15:
print(Secondary)
else age<=17:
print(Sr Secondary)
(v) a=b=c=12,13,14
if (a>=b or a<=c and a+c<=b):
print("A")
ELSE print(a+b+c)
4. Each of the following code segments has some error(s). Rewrite the correct code underlining all the
corrections made. Minimum changes should be made the code so that it executes:
(i) a=int(input("Enter a number: "))
c==1
for b in range (a,a*10.0,a)
c=*b
print(a,b,c)
(v) x=123045
while x%10:
x=//10
print(x,sep="--")
else print(a)
(vi) x=123045
while x%10:
d=x%10
for i in range(d):
print(i)
else: print (d)
print(x,sep='--')
x/=10
else print(a)
(viii) a==10
while a=>0:
if a%2=0:
print(a)
else:
print(a//2)
a-=1
(ix) d1=dict.fromkeys('banana')
d2=fromkeys('pineapple','apple')
d1.update{d2}
for k in d1.keys:
if k in d2
print(d2[k], end=' ')
else: print(d1[k])
(xi) 30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
Else:
print (K+3)
5. Each of the following code segments has some error(s). Rewrite the correct code underlining all the
corrections made. Minimum changes should be made the code so that it executes:
(i) a=[1,2,3,2,1]
for x in range(a):
print(x)
(ii) a=["Umang","Usman","Utkarsh","Umedh"]
for x in range(len(a)):
print(a(x))
(iii) A=[]*5
for i in range(5):
A[i]=i+2
print(A[])
print([A])
A[2:]=A
A[2:5]=8,9,10
6. The following code is written to input a positive integer and display all its even factors in descending
order. This code has some errors. Rewrite the correct code and underline the corrections made.
n=input("Enter a positive integer: ")
for i in range(n):
if i%2:
if n%i==0:
print(i,end=' ')
7. The following code is written to input an integer and display its first 10 multiples (from 1 to 10). This
code has some errors. Rewrite the correct code and underline the corrections made.
n=int(input(Enter an integer: ))
for i in range(1,11):
m=n*j
print(m;End=' ')
8. The following code is written to input an integer and display its factorial. This code has some errors.
Rewrite the correct code and underline the corrections made.
(Note: Factorial of a number n is the product 1x2x3. . .n)
n=int(input("Enter a positive integer: ")
f=0
for i in range(n):
f*=i
print(f)
9. The following code is written to create and display a list of 10 2-digit random integers. This code has
some errors. Rewrite the correct code and underline the corrections made.
import randint from random
nums=list[]
for i in range 10:
nums.append(randint(99,10))
print(nums)
10. The following code is written to create a list of 20 2-digit random integers, and then to remove all the
odd multiples of 3 from the list. This code has some errors. Rewrite the correct code and underline
the corrections made.
Import random
nums=(randint(10,99) for i in range(20))
i=0
while i<nums:
if nums[i]%3==0 and nums[i]%2==0:
del nums[i]
else i+=1
11. The following code is written to create a list of 10 2-digit random integers, and then copy all the
multiples of 5 from this list to a tuple. This code has some errors. Rewrite the correct code and
underline the corrections made.
from randint import random
nums=[randint(10,99) for i in range(10)]
t=tuple
for num in nums:
if num%5=0: t+=(num)
12. The following code is written to create tuple of 10 integers which are input from the user. The code
then finds the sum of all the multiples of 5 present in the tuple. This code has some errors. Rewrite
the correct code and underline the corrections made.
t=()
for i in range(10):
num=int(input("Enter an integer: ")
t+=num
s=0
for i in range(10):
if t(i)//5==0:
s+=t[i]
13. The following code is written to input an integer and check whether it is prime or not. This code has
some errors. Rewrite the correct code and underline the corrections made.
(Note: A prime number is a number which does not have any factor other than 1 and itself)
def prime():
n=int(input("Enter number to check: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n')
14. The following code is written to display all the 2-digit multiples of 4 and 5 in the interval 1 to 50. This
code does not run due to incorrect indentation. Rewrite the code with correct indentation so that it
produces the desired result.
for val in range(1,51):
if val%4==0:
print (val,end=' ')
else:
if val%5==0:
print (val,end=' ')
else:
continue
15. The code given below accepts a number as an argument and returns the reverse number. Observe
the following code carefully and rewrite it after removing all syntax and logical errors. Underline all
the corrections made.
define reverse(n):
rev=0
While n>0:
d=n/10 #
rev=rev*10+d
n//=10
return rev #
print(reverse(1024))
38. To display the index number of ch in the string S1. The statement should not raise any exception if ch is
not found in S1.
39. To display S3 after removing all the leading whitespaces from it.
40. To display S3 after removing all the trailing whitespaces from it.
41. To display S3 after removing all the leading and trailing whitespaces from it.
42. To display a list of all the words in the string S4, assuming that S4 is already defined.
43. To get a sorted (ascending order) list of the characters of S1.
44. To get a sorted (descending order) list of the characters of S2.
45. To store the largest character of S1 in variable high, and the smallest character of S2 in variable low. (The
largest character is the character with highest Unicode value and the smallest character is the character with
the lowest Unicode value)
If T1 = (1,2,3,2,1,2,4,2, . . . ) and T2= 'E', 'x', 'p', 'e', 'n', 's', 'e', 's', then
write a statement to perform each of the following tasks. Each task should be done using one statement only.
(Answer using built-in functions / methods, Slicing, and +, = ,+= operators only):
46. To create an empty tuple with name T3.
47. To create a tuple T4 with the string 'Campground' as its only element.
48. To create a tuple T5 which contains first 3 elements of T1 followed by last 3 elements of T2.
49. To display the number of elements in T2.
50. To display the total number of elements in T1 and T2.
51. To redefine T1 so that it contains all its existing elements followed by T2 as its last element.
52. To redefine T1 so that it contains all its existing elements followed by all the elements of T2.
53. To redefine T1 so that it contains its first 3 exiting elements, followed by T2 as an element, followed by all
the remaining elements of T1.
54. To count the occurrences of 'e' in T1.
55. To count the occurrences of T1[3] in T2.
56. To display the index of the first occurrence of 's' in the tuple T2.
57. To display the index of the second occurrence of 's' in the list T2.
58. To create a list L6 which stores the sorted elements of T1 without affecting T1.
59. To display the smallest element and the largest element of T1.
60. To display the sum of all the elements of T1.
75. To display the value of D2[k] , where k is a variable. If the key k is not found in the dictionary D2, then
add the key value pair k:'Kite' and display the corresponding value (i.e., Kite).
76. To display a list of sorted keys of D1.
77. To display a list of sorted values of D2.
78. To display the value corresponding to the highest key of D1.
79. To display the value corresponding to the smallest key of D2.
80. To add all the key-value pairs of D1 to D2 (Assuming that D1 and D2 have no common key).
then after reversal the list should contain 10, 1, 6, 19, 9, 7, 14, 3, 15, 2
7. Write a function Alternate(nums), where nums is a list. The function should rearrange the list nums in
such a way that the values of each pair of consecutive elements are interchanged. For example:
If the list initially contains 2, 5, 9, 14, 17, 8
Then after rearrangement the list should contain 5, 2, 14, 9, 8, 17
8. Write a function combine(A,B,C), where A and B are equi-sized lists of numbers, and C is an empty list.
The function should combine the elements of A and B into C such that C[i]=2*A[i]+3*B[i], where i
is a valid index.
9. Write a function in calculate(A), where A is a list of integers. The function should divide all the elements
of the list by 5 which are divisible by 5, and multiply the other list elements by 2.
10. Write a function merge(A,B,C) where A and B are equi-sized lists and C is an empty list. The function
should merge the elements of A and B into C such that all even positions of C are occupied by the elements of
A and all odd positions of C are occupied by the elements of B. For example:
If A=['a','b','c','d'] and B=[10,2,5,6], then C should be
['a',10,'b',2,'c',5,'d',6]
11. Write a function in replace(A), where A is a list of integers. The function should replace each element
of the list having even value with its half and each element having odd value with its double. For example, if
A=[3, 4, 5, 16, 9] then after execution of the function, the list A should be [ 6, 2, 10, 8, 18]
12. Write a function shortName(ft,md,last), where ft,md, and last are strings respectively
representing the first name, middle name, and the last name of a person. The function should return the short
name of the person. For example, if ft='Chander', md='Mohan', and last='Subramaniam', then
the function should return 'C. M. Subramaniam'.
13. Write a function that accepts a string as a parameter and checks whether it is a palindrome or not. The checking
should not be case sensitive. The function should display 'Palindrome' or 'Not Palindrome' as per
the case.
14. Write a function to palindrome(n), where n is a positive integer. The function should input n strings from
the user and return the total number of palindrome strings entered by the user.
15. Write a function to input a string from the user and display the number of digits, number of uppercase
alphabets, number of lowercase alphabets, and number of whitespace characters appearing in the string. (space,
'\t', and '\n' are whitespace characters.)
16. Write a function to input a string and replace each occurrence of multiple consecutive spaces, if any, with a
single space in the string. Then return the resultant string. For example, if the user enters '1 2 3 4
5 6666 7 8', then the function should return '1 2 3 4 5 6666 7 8'.
17. Write a function to input a string and count the number of words not starting with an uppercase vowel in the
string. Two consecutive words may be separated by one or more white spaces.
18. Write a function characters(S), where S is a string. The function should return a list of distinct
characters appearing in the string S. For example, if S='Apple in Pineapple', then the function should
return ['A', 'p', 'l', 'e', ' ', 'i', 'n', 'P', 'a']
19. Write a function frequency(S), where S is a string. The function should display the frequency of each
alphabet appearing in the string. (Alphabet counting should not be case-sensitive) For example, if S= 'Shine
in 2025', then the output should be:
S - 1
H - 1
I - 2
N - 2
E - 1
Hint: Use a dictionary to form the frequency table.
20. Write a function sortWords(S), where S is a string. The function should display all the words of the string
in alphabetical order. For example, if S='NCERT CBSE NIOS KV', then the output should be:
['CBSE', 'KV', 'NCERT', 'NIOS']
21. Write a function vowelStar(S,ch), where S and ch are strings. The function should replace each lower
case vowel of the string S with the string ch, and return the resultant string. For example, if S='Enormous
Influence' and ch='i*', then the function should return 'Eni*rmi*i*s Infli*i*nci* '.
Example :
If the content of the file STORY.TXT is as follows :
Success shows others that we can do it. It is possible to
achieve success with hard work. Lot of money does not mean
SUCCESS. Speak to successful people to know more.
12. Write function definition for TOWER() in PYTHON to read the content of a text file WRITEUP.TXT,
count the presence of word TOWER and display the number of occurrences of this word.
Note :
- The word TOWER should be an independent word
- Ignore type cases (i.e. lower/upper case)
- A word in the file may end with a white space, a . (dot), or a , (comma).
Example:
If the content of the file WRITEUP.TXT is as follows:
13. Write the function definition for WORD4CHAR() in PYTHON to read the content of a text file
FUN.TXT, and display all those words, which have four characters in it.
Example:
If the content of the file Fun.TXT is as follows:
When I was a small child, I used to play in the
garden with my grand mom. Those days were amazingly
funful and I remember all the moments of that time
14. Write function definition for DISP3CHAR() in PYTHON to read the content of a text file
KIDINME.TXT, and display all those words, which have three characters in it. Example:
If the content of the file KIDINME.TXT is as follows:
15. Write a function in Python to copy the contents of a text file into another text file. The names of the
files should be input from the user.
16. Write a function in Python which accepts two text file names as parameters. The function should
copy the contents of first file into the second file in such a way that all multiple consecutive spaces
are replaced by a single space. For example, if the first file contains:
Self conquest is the
greatest victory .
then after the function execution, second file should contain:
Self conquest is the
greatest victory .
17. Write a function to display the last line of a text file. The name of the text file is passed as an
argument to the function.
18. Write a Python function to read and display a text file 'BOOKS.TXT'. At the end display number of
lowercase characters, uppercase characters, and digits present in the text file.
19. Write a Python function to display the size of a text file after removing all the white spaces (blanks,
tabs, and New line characters).
20. Consider the following code:
ch = "A"
f=open("data.txt",'a')
f.write(ch)
print(f.tell())
f.close()
What is the output if the file content before the execution of the program is the string "ABC"? (Note that
" " are not the part of the string)
21. Write a single statement to display the contents of a text file named "abc.txt"
22. Write a function in PYTHON to display the last 3 characters of a text file "STORY.TXT".
def CSVRead():
try:
with open('books.csv','r') as csvf:
cr=______ #Statement-4
for r in cr:
if ______: #Statement-5
print(r)
except:
print('File Not Found')
CSVOpen()
CSVRead()
You, as an expert of Python, have to provide the missing statements and other related queries
based on the above code of Ramya.
(a) Write the appropriate mode in which the file is to be opened. (Statement 1)
(b) Which statement will be used to create a csv writer object in Statement 2.
(c) Write the correct option for Statement 3 to write the names of the column headings in the CSV
file books.csv
(d) Write statement to be used to read the csv file in Statement 4.
(e) Fill in the appropriate statement to check the field Title starting with 'K' for Statement 5.
7. Following is an incomplete python code to create a CSV File 'Student.csv' (content shown below).
Complete the code by filling in the missing parts.
CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import__________ #Statement-1
fh = open(________, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [_____] #Statement-4
data.append(rec)
stuwriter. _____ (data) #Statement-5
fh.close()
8. Following is an incomplete python code to create a CSV File 'Student.csv' (content shown below).
Complete the code by filling in the missing parts by following the hints a) to d)
_________________ #Statement 1
headings = ['Country','Capital','Population']
data = [['India', 'Delhi',130],['USA','WashingtonDC',50],
[Japan,Tokyo,2]]
f = open('country.csv','w', newline="")
csvwriter = csv.writer(f)
csvwriter.writerow(headings)
________________ #Statement 2
f.close()
f = open('country.csv','r')
csvreader = csv.reader(f)
head=_________________ #Statement 3
print(head)
for x in __________: #Statement 4
if int(x[2])>50:
print(x)
a) Statement 1 – Write the python statement that will allow Sudheer work with csv files.
b) Statement 2 – Write a python statement that will write the list containing the data available as a
nested list in the csv file
c) Statement 3 – Write a python statement to read the header row in to the head object.
d) Statement 4 – Write the object that contains the data that has been read from the file.
9. Manoj Kumar is writing a program to create a CSV file "user.csv" which will contain user name and
password for some entries. He has written the following code. As a programmer, help him to
successfully execute the given task.
import ______________ #Line1
def addCsvFile(UserName, Password):
fh=open('user.csv','_',newline='') #Line2
Newfilewriter=csv.writer(fh)
Newfilewriter.writerow([UserName,Password])
fh.close()
# csv file reading code
def readCsvFile(): #to read data from CSV file
with open('user.csv','r') as newFile:
newFileReader=csv.______(newFile) #Line3
for row in newFileReader:
print(row)
addCsvFile('Arjun','123@456')
addCsvFile('Arunima','aru@nima')
addCsvFile('Frieda','myname@FRD')
readCsvFile()
OUTPUT___________________ #Line 4
(a) What module should be imported in #Line1 for successful execution of the program?
(b) In which mode file should be opened to work with user.csv file in #Line2
(c) Fill in the blank in #Line3 to read data from csv file
(d) Write the output he will obtain by executing the code in #Line5
10. Write a function in PYTHON to update a binary file "LAPTOP.DAT" containing the records of
following type.
[ModelNo, RAM, HDD, Details]
where ModelNo, RAM, HDD are integers, and Details is a string.
The function should update the RAM to 16 for all those records where HDD is 1024 or above.
11. Write a function in PYTHON to update a binary file "BOOK.DAT", assuming the binary file is
containing the records of the following type:
{"BookNo":value, "Book_name":value}
The function should add a key-value pair to each record. The key should be "Edition" and
value should be input from the user.
12. Following is the structure of each record in a data file named "PRODUCT.DAT".
{"p_code":value, "p_desc":value, "stock":value}
The values for p_code and prod_desc are strings, and the value for stock is an integer.
Write a function in PYTHON to delete all those records from the file where prod_desc is a blank
string.
13. A binary file, MIC.DAT, contains data of some mics in an electronics shop. Each record is stored
as a dictionary in the following format:
{Code: [Brand, Type, Cost]}
(Code, Brand, Type are strings, Price is integer)
Write a function in Python to delete all those records from the file whose Type is 'BT'.
14. A binary file, SPEED.DAT, contains records with the following structure:
(vehicletype, no_of_wheels)
Where vehicletype is a string, and no_of_wheels is an integer.
Write a function copy4w() to copy all those records, where no_of_wheels is 4, from SPEED.DAT
to a new file Four_Wheels.DAT.
15. A binary file, MIC.DAT, contains data of some mics in an electronics shop. Each record is stored
as a dictionary in the following format:
{Code: [Brand, Type, Cost]}
(Code, Brand, Type are strings, Price is integer)
Write a function in Python to remove all those records from the file whose Type is 'BT' and write
these to a new binary file BT.DAT.
16. Write a function which takes two file names as parameters. The function should read the first file
(a text file), and stores the index of this file in the second file (a binary file). The index should tell
the line numbers in which each of the words appear in the first file. If a word appears more than
once, the index should contain all the line numbers containing the word.
Stacks
1. What is a stack? In Python, should we implement stacks using a list or a tuple? Justify your answer.
2. Define PUSH and POP operations w.r.t. stacks.
3. Give any two characteristics of stacks.
4. Expand the term LIFO. Which data structure facilitates LIFO operations?
5. Julie has created a dictionary containing names and marks as key:value pairs of 6 students. Write a program,
with separate user defined functions to perform the following operations:
• Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
• Pop and display the content of the stack.
For example, if the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be:
TOM ANU BOB OM
6. Alam has a list containing 10 integers. You need to help him create a program with separate user defined
functions to perform the following operations based on this list.
• Traverse the content of the list and push the even numbers into a stack.
• Pop and display the content of the stack.
For Example, if the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 22 98 56 34 12
7. Jomia has created the following dictionary containing Indian names of some herbs and their corresponding
names in English:
Herbs={'Adrak':'Ginger', 'Amla': 'Gooseberry', 'Babool': 'Indian
Gum', 'Dhania': 'Coriander', 'Lahsun':'Garlic', 'Tulsi': 'Basil'}
Write a program, with separate user defined functions to perform the following operations:
• Push the item (key, value pair) of the dictionary into a stack, where the corresponding value
(English name) starts with 'G'.
• Pop and display the content of the stack.
8. Write a program to input an integer and display all its prime factors in descending order, using a stack. For
example, if the input number is 2100, the output should be: 7 5 5 3 2 2 (because prime factorization of 2100
is 7x5x5x3x2x2)
Hint: Smallest factor of any integer is guaranteed to be prime.
9. Ismail has created the following list:
from random import randint
nums=[randint(10,99) for I in range(20)]
Write a program, with separate user defined functions to perform the following operations:
• Push the even numbers from the list into a stack, and then push all the odd numbers from
the list into the same stack.
• Pop and display the content of the stack.
Assuming standard definitions of functions PUSH() and POP(), redraw the stack after performing each of
the following operations:
POP(S); POP(S); PUSH(S,8); PUSH(S,3); POP(S); PUSH(S,9)
11. Find the output of the following code:
stack=[]
def push(s,n):
s.append(n)
def pop(s):
if s!=[]:
return s.pop()
print(pop(stack))
push(stack,5); push(stack,10)
pop(stack); push(stack,5)
print(pop(stack)*2)
push(stack,6)
push(stack,'a')
pop(stack); push(stack,'b')
print(pop(stack))
print(stack[0],stack[-1])
print(len(stack))
Assuming standard definitions of functions PUSH() and POP(), redraw the stack after performing each of
the following set of operations:
PUSH(S,8); POP(S); PUSH(S,3); POP(S); POP(S); PUSH(S,9)
14. Write a function in Python, Push(SItem) where , SItem is a dictionary containing the details of stationary
items in the format {Sname:price}.
The function should push the names of those items in the stack who have price greater than 75. Also display
the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
Notebook
Pen
The output should be:
The count of elements in the stack is 2
2. MySQL is a/an:
a) Database b) Relational Database
c) RDBMS d) Table
12. Which of the following constraints allows Null but does not allow duplicate values?
a) Primary Key b) Foreign Key
c) Not Null d) Unique
13. Which of the following constraints does not allow Null but allows duplicate values?
a) Primary Key b) Foreign Key
c) not null d) unique
17. If a table has 5 rows and 3 columns then its degree is:
a) 3 b) 5
c) 8 d) 15
18. If a table has 5 rows and 3 columns then its cardinality is:
a) 3 b) 5
c) 8 d) 15
19. A table contains data of 50 students of a class. The table has 6 columns. The roll numbers of the students
are integers from 51 to 100. What is the degree of this table?
a) 50 b) 6
c) 51 d) set of integers from 51 to 100.
20. A table contains data of 50 students of a class. The table has 6 columns. The roll numbers of the students
are integers from 51 to 100. What is the cardinality of this table?
a) 50 b) 6
c) 51 d) set of integers from 51 to 100.
21. A table contains data of 50 students of a class. The table has 6 columns. The roll numbers of the students
are integers from 51 to 100. What is the domain of the column RollNumber?
a) 50 b) 6
c) 51 d) set of integers from 51 to 100.
22. A table contains data of 10 students of a class. The domain of the column Name is the set {'Aman',
'Daman', 'Gaman', 'Naman', 'Raman', 'Yaman'}. What is the degree of this table?
a) 1 b) 6
c) 10 d) Cannot be determined with the given information.
23. A table contains data of 10 students of a class. The domain of the column Name is the set {'Aman',
'Daman', 'Gaman', 'Naman', 'Raman', 'Yaman'}. What is the cardinality of this table?
a) 1 b) 6
c) 10 d) Cannot be determined with the given information.
24. A table contains data of 10 students of a class. The domain of the column Name is the set {'Aman',
'Daman', 'Gaman', 'Naman', 'Raman', 'Yaman'}. What is the best suitable datatype
for the column Name of this table?
a) char b) varchar
c) int d) float
27. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is a column named Sno in both the
tables A and B, then what is the degree of the Cartesian Product of A and B?
a) 10 b) 11
c) 35 d) 300
28. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is a column named Sno in both the
tables A and B, then what is the cardinality of the Cartesian Product of A and B?
a) 10 b) 11
c) 35 d) 300
29. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is a column named Sno in both the
tables A and B, then what is the degree of the Natural Join of A and B?
a) 10 b) 11
c) 35 d) 300
30. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is no common column in the tables A
and B, then what is the degree of the Cartesian Product of A and B?
a) 10 b) 11
c) 35 d) 300
31. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is no common column in the tables A
and B, then what is the cardinality of the cartesian product of A and B?
a) 10 b) 11
c) 35 d) 300
32. A relational database contains two tables A and B. The degrees of A and B are 5 and 6 respectively.
The cardinalities of A and B are 15 and 20 respectively. If there is no common column in the tables A
and B, then what is the degree of the natural join of A and B?
a) 10 b) 11
c) 35 d) 300
33. Some SQL commands are categorized as DML commands. DML stands for:
a) Disk Manipulation Language b) Data Management Language
c) Disk Management Language d) Data Manipulation Language
34. Some SQL commands are categorized as DDL commands. DDL stands for:
a) Disk Description Language b) Data Definition Language
c) Disk Definition Language d) Data Description Language
43. Which SQL command is used to view the list of available databases?
a) View Databases; b) Show Databases;
c) List Databases; d) Desc Databases;
45. Which SQL command is used to view the list of available tables in the current database?
a) View tables; b) Show tables;
c) List tables; d) Desc tables;
47. Which SQL command is used to add new columns to an existing table?
a) Update b) Alter
c) Insert d) Select
48. Which SQL command is used to remove columns from an existing table?
a) Update b) Alter
c) Insert d) Select
50. Which SQL command is used to remove constraints from an existing table?
a) Update b) Alter
c) Insert d) Select
54. Which SQL command is used to make changes to existing data in a table?
a) Update b) Alter
c) Insert d) Select
56. Which SQL command does not affect the data or structure of a table?
a) Update b) Alter
c) Insert d) Select
57. Which of the following clauses is used to retrieve sorted data from a table?
a) distinct b) group by
c) order by d) like
58. Which of the following clauses is used to specify pattern matching condition in where clause?
a) distinct b) group by
c) order by d) like
59. Which of the following clauses is used to specify that duplicate entries from a column are not required
to be selected?
a) distinct b) group by
c) order by d) like
60. If a table Employee has a column Name, then what will be the output of the following query:
Select * from employee where name like '_A%';
a) All the records of the table. b) All the records of the table in which Name
contains A.
c) All the records of the table in which A is the d) All the records of the table in which A is the
second character of the Name. second last character of the Name.
61. If a table Employee has a column Name, then what will be the output of the following query:
Select * from employee where name like '%A%';
a) All the records of the table. b) All the records of the table in which Name
contains A.
c) All the records of the table in which A is the d) All the records of the table in which A is the
second character of the Name. second last character of the Name.
62. If a table Employee has a column Name, then what will be the output of the following query:
Select * from employee where name like '%A_';
a) All the records of the table. b) All the records of the table in which Name
contains A.
c) All the records of the table in which A is the d) All the records of the table in which A is the
second character of the Name. second last character of the Name.
63. If a table Employee has a column Name, then what will be the output of the following query:
Select * from employee where name like '%A';
a) All the records of the table in which A is the b) All the records of the table in which Name
last character of Name. does not contain A.
c) All the records of the table in which A is the d) All the records of the table in which A is the
second character of the Name. second last character of the Name.
64. If a table Employee has a column Name, then what will be the output of the following query:
Select * from employee where name like '%A' or name like 'A%';
a) All the records of the table in Name start b) All the records of the table in which Name
with A and ends with A. is AA.
c) All the records of the table in which Name d) All the records of the table in which Name
starts and ends with A. contains A in the beginning or end or at both
places.
65. If a table Employee has a column Name, then choose the query which can replace the following query:
Select * from employee where name like '%A' and name like 'A%';
a) Select * from employee where b) Select * from employee where
name like 'A%A'; name like '%A%';
c) Select * from employee where d) Select * from employee where
name like '%AA%'; name like 'A%A%';
66. If a table Employee has a column Name, then choose the query which can replace the following query:
Select * from employee where name in ('Dua','Jaz','Raj');
a) Select * from employee where name like ('Dua','Jaz','Raj');
b) Select * from employee where name=('Dua','Jaz','Raj');
c) Select * from employee where name='Dua' and name='Jaz' and
name='Raj';
d) Select * from employee where name='Dua' or name='Jaz' or
name='Raj';
67. If a table Employee has a column Name, then choose the query which can replace the following query:
Select * from employee where name not in ('Dua','Jaz','Raj');
a) Select * from employee where name not like ('Dua', 'Jaz',
'Raj');
b) Select * from employee where name!=('Dua','Jaz','Raj');
c) Select * from employee where name!='Dua' and name!='Jaz' and
name!='Raj';
d)Select * from employee where name!='Dua' or name!='Jaz' or
name!='Raj';
68. If a table Employee has a column Age, then choose the query which can replace the following query:
Select * from employee where Age between 24 and 55;
a) Select * from employee where Age>=24 and Age<=55;
b) Select * from employee where Age>=24 or Age<=55;
c) Select * from employee where Age>24 and Age<55;
d)Select * from employee where Age>24 or Age<55;;
69. If a table Employee has a column Age, then what will be the output of the following query:
Select * from employee where Age>35;
a) All the records of the table in which Age is b) All the records of the table in which Age is
more than 35. 35 or more.
c) All the records of the table in which Age is d) No output - The query has an error.
35 and more.
70. If a table Employee has a column Age, then what will be the output of the following query:
Select * from employee having Age>=35;
a) All the records of the table in which Age is b) All the records of the table in which Age is
more than 35. 35 or more.
c) All the records of the table in which Age is d) No output - The query has an error.
35 and more.
72. Which aggregate function in SQL can be used to find the cardinality of a table?
a) sum() b) max()
c) count() d) None of these
75. Which aggregate function in SQL is valid for numeric data only?
a) sum() b) max()
c) count() d) min()
76. A table T1 has a field F1 of char(10) type. The table contains only two records and the column
F1contains the values 'p' and '8'. In this context what will be the output of the following query?
Select sum(F1) from T1;
a) 8 b) '8'
c) 0 d) Error
77. A table T1 has a field F1 of char(10) type. The table contains only two records and the column
F1contains the values 'p' and '8'. In this context what will be the output of the following query?
Select avg(F1) from T1;
a) 8 b) '8'
c) 4 d) '4'
78. If a table Employee has a column Age, then what will be the output of the following query:
Select count(Age) from employee;
a) Number of records in the table. b) Number of records in which Age is not
NULL.
c) Number of records in which Age can be d) All the value of Age column.
counted.
79. If a table Employee has a column Age, then what will be the output of the following query:
Select count(Age) from employee;
a) Number of records in the table. b) Number of records in which Age is not
NULL.
c) Number of records in which Age can be d) All the value of Age column.
counted.
80. If a table Employee has columns Dept and Age, then which of the queries will retrieve the data
sorted on Dept, and sorted on Age within each Dept:
a) Select * from employee order by Dept and Age;
b) Select * from employee order by Dept within Age;
c) Select * from employee order Dept, Age;
d)Select * from employee order by Dept+Age;
81. If a table Employee has columns Dept and Age, then which of the queries will retrieve the data in
the ascending order of Dept, and sorted in descending order of Age within each Dept:
a) Select * from employee order by Dept-Age;
b) Select * from employee order by Dept, Age desc;
c) Select * from employee order Dept, Desc Age;
d)Select * from employee order by Dept, reverse Age;
82. If a table Employee has columns Dept and Age, then which of the queries will retrieve the data
showing average Age in each Dept:
a) Select avg(age) from employee order by Dept;
b) Select dept, age from employee group by Dept;
c) Select avg(age), dept from dept wise;
d)Select dept, avg(age) from employee group by dept;
83. Which of the following queries will add a column BALANCE, of type int, to the table ITEM:
a) Alter table item set Balance (int);
b) Alter table ITEM add Balance (int);
c) Alter table item add column Balance int;
d)Alter table item set column Balance int;
84. Which of the following queries will add a columns BALANCE and GRP, of type int and CHAR(5)
respectively, to the table ITEM:
a) Alter table item add balance int, grp char(5);
b) A Alter table item add (balance int, grp char(5));
c) Alter table item add (balance, grp int,char(5));
d)Alter table item (balance int, grp char(5);
85. Which of the following queries will remove the column BALANCE from the table ITEM:
a) Alter table item delete column balance;
b) Alter table item drop column balance;
c) Alter item delete column balance;;
d)Alter item drop balance;
86. Which of the following is not a valid difference between DELETE and DROP commands of SQL:
a) DELETE is a DML command and DROP is a DDL command;
b) DELETE can delete a table whereas DROP can DROP a table.
c) DELETE affects the data whereas DROP affects the structure of the database;
d) DELETE can reduce the cardinality of a table, whereas DROP can change the Degree of a
table
87. If a table Employee has columns Code, Dept and Age, then which of the following queries will
make Code the Primary Key of the table:
a) Alter table employee set Primary Key (Code);
b) Update employee set Code = Primary Key;
c) Alter table employee add Primary Key (Code);
d)Update table employee add Primary Key (Code);
88. If the column Code is the Primary Key of a table Employee, then which of the following queries will
remove the Primary Key of the table:
a) Alter table employee delete Code;
b) Update employee set Primary Key = None;
c) Alter table employee drop Primary Key;
d)Update table employee drop Primary Key (Code);
89. If a table Employee has columns Proj, Dept,DOS and DOE, then which of the following queries
will make Proj+Dept the Primary Key of the table:
a) Alter table employee set Primary Key (Proj), Primary Key(Dept);
b) Alter table employee set Primary Key (Proj+Dept);
c) Alter table employee set Primary Key (Proj,Dept);
d) Alter table employee set Primary Keys (Proj,Dept);
90. If a table Employee has a composite Primary Key consisting of columns Proj and Dept, then which
of the following statements is False:
a) Proj column cannot accept NULL
b) Dept column cannot accept NULL
c) One of the columns Proj or Dept can be NULL for a record
d) Neither of the columns Proj or Dept can be NULL for any record
91. If two table A and B, in a database, have a common field named Code, then which of the following
commands will display the cartesian product of these two tables:
a) Select * from A and B;
b) Select Code from A, B;
c) Select * from A,B;
d)Select * from A cartesian B;
92. If two table A and B, in a database, have a common field named Code, then which of the following
commands will display the natural join of these two tables:
a) Select * from A natural B;
b) Select * from A natural join B;
c) Select * from A,B;
d)Select * from A, B join on Code;
93. If two table A and B, in a database, have a common field named Code, then which of the following
commands will show an error:
a) Select * from A, B;
b) Select Code from A, B;
c) Select Code from A natural join B
d)Select * from A natural join B;
94. If two table A and B, in a database, have a common field named Code, then which of the following
statements is True:
a) Code will not appear in the cartesian product of A and B
b) Code will appear once in the cartesian product of A and B
c) Code will appear twice in the cartesian product of A and B
d) None of the above
95. If two table A and B, in a database, have a common field named Code, then which of the following
statements is False:
a) Code will appear once in the natural join of A and B
b) Code will appear twice in the cartesian product of A and B.
c) Cardinality of the Cartesian product of A and B will be more than the cardinality of natural
join of A and B.
d) Cardinality of the Cartesian product of A and B will be less than or equal to the cardinality
of natural join of A and B.
96. In context of Python - Database connectivity, the function fetchone() is a method of which
object?
a) connection b) database
c) cursor d) query
97. In context of Python - Database connectivity, the function commit() is a method of which object?
a) connection b) database
c) cursor d) query
98. In context of Python - Database connectivity, the function execute() is a method of which object?
a) connection b) database
c) cursor d) query
99. In context of Python - Database connectivity, the function cursor() is a method of which object?
a) connection b) database
c) cursor d) query
16. Assertion(A): If the column C1 is the Primary Key of a table T1, then both of the following queries
will produce the same result.
select C1 from T1;
select distinct(C1) from T1;
Reasoning (R): C1 cannot have any NULL values.
17. Assertion(A): If the column C1 is the Primary Key of a table T1, then both of the following queries
will produce the same result.
select C1 from T1;
select distinct(C1) from T1;
Reasoning (R): C1 cannot have any duplicate values.
18. Assertion(A): If the column C1 is an Alternate Key of a table T1, then both of the following queries
will produce the same result.
select C1 from T1;
select distinct(C1) from T1;
Reasoning (R): C1 cannot have any NULL values.
19. Assertion(A): The following SQL statement will give the output 5
select 2+3;
Reasoning (R): Select command can be used to evaluate expressions.
20. Assertion(A): If T1 is a table with columns C1, C2, and C3, then the following statement will give
an error:
select 2+3 from T1;
Reasoning (R): 2+3 is not a column of T1.
21. Assertion(A): If T1 is a table with columns C1, C2, and C3, then the following statement will be
executed successfully:
select C1 C2 from T1;
Reasoning (R): In the above statement C2 will be considered an alias of C1.
22. Assertion (A): We can use WHERE clause instead of HAVING clause with GROUP BY clause.
Reasoning (R): WHERE and HAVING both are used to apply conditions.
23. Assertion (A): We cannot use WHERE clause instead of HAVING clause with GROUP BY clause.
Reasoning (R): WHERE and HAVING both are used to apply conditions.
24. Assertion (A): We cannot use WHERE clause instead of HAVING clause with GROUP BY clause.
Reasoning (R): WHERE clause is used to apply conditions on individual rows, whereas HAVING
clause is used to apply conditions on groups.
25. Assertion (A): A Foreign Key is an attribute whose values are derived from the Primary Key of
another table.
Reasoning (R): A Foreign Key is used to establish relationship between two tables.
26. Assertion (A): A Foreign Key column cannot accept NULL values.
Reasoning (R): A Foreign Key is an attribute whose values are derived from the primary Key of
another table.
27. Assertion (A): The domain of the Foreign Key column of a table is same as that of the Primary Key
to which it references.
Reasoning (R): A Foreign Key is an attribute whose values are derived from the Primary Key of
another table.
28. Assertion (A): The cardinality of the Natural join of two tables cannot be more than the cardinality of
their Cartesian Product
Reasoning (R): Natural join of two tables is obtained after filtering the records of their Cartesian
Product.
29. Assertion (A): The cardinality of the Natural join of two tables can be more than the cardinality of
their Cartesian Product
Reasoning (R): Natural join of two tables is obtaining by applying a condition on their Cartesian
Product.
30. Assertion (A): The cardinality of the Natural join of two tables cannot be more than the cardinality of
their Cartesian Product
Reasoning (R): Natural join of two tables is same as their Cartesian Product.
18. Explain the usage of HAVING clause in GROUP BY command in RDBMS with the help of an example.
19. What is the difference between degree and cardinality of a table? What is the degree and cardinality of the following
table?
ENo Name Salary
101 John Fedrick 45000
103 Raya Mazumdar 50600
20. Give a suitable example of a table with sample data and illustrate Primary and Alternate keys in it.
21. Observe the following table carefully and write the names of the most appropriate columns, which can be
considered as (i) candidate keys and (ii) primary key.
Id Product Qty Price Transaction Date
101 Plastic Folder 12" 100 3400 2014-12-14
104 Pen Stand Standard 200 4500 2015-01-31
105 Stapler Medium 250 1200 2015-02-28
109 Punching Machine Big 200 1400 2015-03-12
103 Stapler Mini 100 1500 2015-02-02
22. Observe the following STUDENTS and EVENTS tables carefully and write the name of the RDBMS operation
which will be used to produce the output as shown in LIST. Also, find the Degree and Cardinality of the LIST.
STUDENTS EVENTS
No Name EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha
LIST
NO NAME EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
1 Tara mani 1002 IT Quiz
2 Jaya Sarkar 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha 1001 Programming
3 Tarini Trikha 1002 IT Quiz
34. Display maximum fee, minimum fee, average fee, total fee, and number of entries in the fee column for
class 5 students.
35. Display Lowest scholarship and Highest scholarship. Lowest Scholarship is calculated as 2 times the
lowest fee, and highest scholarship is calculated as 2 times the highest fee.
36. Display section wise number of students from the table stdmaster.
37. Display section wise number of students from the table stdmaster only for those sections where
number of students is more than 1.
38. Display section wise number of students whose names start with 'A' from the table stdmaster.
39. Display section wise number of students whose names start with 'A' from the table stdmaster, but only
for those sections where such number is more than 2.
40. Create a table HouseAct (To store House Activities records) with the following structure:
SNo Field Type Constraint
1. AdmNo Char(10) Foreign key references stdmaster(AdmNo)
2. House Varchar(10) Not null
3. Activity varchar(20)
41. Insert the following data into the table HouseAct:
+-----------+---------+-------------+
| admno | house | activity |
+-----------+---------+-------------+
| 200700001 | Peace | Dance |
| 200700002 | Harmony | Music |
| 200800009 | Hope | Quiz |
| 200700002 | Harmony | Dance |
| 200700001 | Peace | Drama |
| 200700002 | Harmony | Photography |
+-----------+---------+-------------+
42. Display all the data from the table HouseAct.
43. Display the cartesian product of stdmaster and HouseAct.
44. Display the natural join of stdmaster and HouseAct.
45. Display all the data from the equijoin of stdmaster and HouseAct.
46. Display admno, name, house, and activity of all the students who are participating in some activity.
47. Display admno, name, class, section, activity of all the students who are participating in some activity.
48. Display admno, name, class, section, activity of all the students who are participating in dance.
49. Using natural join, display admno, name, class, section, activity of all the students who are
participating in some activity.
50. Using natural join, display admno, name, class, section, activity of all the students who are
participating in dance.
51. Add a new column 'grade' of float type to the table HouseAct.
52. Add a new column 'level' of varchar(10) type to the table HouseAct.
53. Display the structure of table HouseAct.
54. Delete the column 'level' from the table HouseAct.
55. Delete all the data from the table stdmaster.
56. Delete all the data from HouseAct.
57. Display names of all the table in the database.
58. Delete the table HouseAct.
59. Delete the database pracSQL.
60. Display the names of all the databases.
ARRIVALS
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 Wood Comfort Double Bed 2003-03-23 25000 25
2 Old Fox Sofa 2003-02-20 17000 20
3 Micky Baby cot 2003-02-21 7500 15
a) To show all information about the Baby cots from the FURNITURE table.
b) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.
c) To list ITEMNAME and TYPE of those items, in which date of stock is before 2002-01-22 from
the FURNITURE table in descending of ITEMNAME.
d) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount percentage is
more than 25 from FURNITURE table.
e) To count the number of items, whose TYPE is "Sofa" from FURNITURE table.
f) To insert a new row in the ARRIVALS table with the following data:
14,"Valvet touch", "Double bed", '2003-03-25', 25000,30
g) Give the output of following SQL statements:
Note: Outputs of the above mentioned queries should be based on original data given in both the
tables i.e., without considering the insertion done in (f) part of this question.
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE,ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE = "Baby
cot";
(iv) Select SUM(Price) from FURNITURE where DATEOFSTOCK < '2002-
02-12'
4. Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (a) to (d)
and give outputs for SQL queries (e1) to (e4)
GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
(a) To display the name of all Games with their Gcodes
(b) To display details of those games which are having PrizeMoney more than 7000.
(c) To display the content of the GAMES table in ascending order of ScheduleDate.
(d) To display sum of PrizeMoney for each of the Number of participation groupings (as shown in
column Number)
(e1) SELECT COUNT(DISTINCT Number) FROM GAMES;
(e2) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
(e3) SELECT SUM(PrizeMoney) FROM GAMES;
(e4) SELECT DISTINCT Gcode FROM PLAYER;
5. Consider the following tables WORKER and PAYLEVEL and answer (A) and (B) parts of this question:
WORKER
ECODE NAME DESIG PLEVEL DOJ DOB
11 Radhey Shyam Supervisor P001 13-Sep-2004 23-Aug-1981
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-June-2009 14-Oct-1983
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
18 Sanya Clerk P002 19-Dec-2005 09-June-1983
PAYLEVEL
PAYLEVEL PAY ALLOWANCE
P001 26000 12000
P002 22000 10000
P003 12000 6000
(A) Write SQL commands for the following statements:
(i) To display the details of all WORKERs in descending order of DOB.
(ii) To display NAME and DESIG of those WORKERs whose PLEVEL is either P001 or P002.
(iii) To display the content of all the WORKERs table, whose DOB is in between ’19-JAN-1984’
and ’18-JAN-1987’.
(iv) To add a new row with the following:
19, ‘Daya kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-Jul-1984’
(B) Give the output of the following SQL queries:
(i) SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
(ii) SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(iii) SELECT Name, Pay FROM WORKER W, PAYLEVEL P WHERE
W.PLEVEL=P.PLEVEL AND W.ECODE<13;
(iv) SELECT PLEVEL, PAY+ALLOWANCE FROM PAYLEVEL WHERE
PLEVEL=’P003’;
6. Consider the following tables CABHUB and CUSTOMER and answer parts (A) and (B):
CABHUB CUSTOMER
VCode VehicleName Make Color Capacity Charges CCode CName VCode
100 Innova Toyota WHITE 7 15 1 Hemant Sahu 101
102 SX4 Suzuki BLUE 4 14 2 Raj Lal 108
104 C Class Merc RED 4 35 3 Feroz Shah 105
105 A-Star Suzuki WHITE 3 14 4 Ketan Dhal 104
108 Indigo Tata SILVER 3 12
7. Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown in (g1) to (g4)
parts on the basis of tables ITEMS and TRADERS:
ITEMS
CODE INAME QTY PRICE COMPANY TCODE
1001 DIGITAL PAD 12i 120 11000 XENITA T01
1006 LED SCREEN 40 70 38000 SANTORA T02
1004 CAR GPS SYSTEM 50 21500 GEOKNOW T01
1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02
1005 PEN DRIVE 32GB 600 1200 STOREHOME T03
TRADERS
TCode TName CITY
T01 ELECTRONIC SALES MUMBAI
T03 BUSY STORE CORP DELHI
T02 DISP HOUSE INC CHENNAI
a) To display the details of all the items in the ascending order of item names (i.e. INAME).
b) To display the number of items, which are traded by each trader, as follows:
T01 2
T02 2
T03 1
c) To display item name and price of all those items, whose price is in range of 10000 and 22000
(both values inclusive).
d) To display the price, item name and quantity (qty) of those items which have quantity more than
150.
e) To display the names of those traders, who are either from DELHI or from MUMBAI.
f) To display the names of the companies and the names of the items in descending order of company
names.
g1) SELECT MAX(PRICE), MIN(PRICE) FROM ITEMS;
g2) SELECT PRICE*QTY AMOUNT FROM ITEMS WHERE CODE-1004;
g3) SELECT DISTINCT TCODE FROM ITEMS;
g4) SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE
I.TCODE=T.TCODE AND QTY<100;
8. Answer the (A) and (B) parts on the basis of the following tables STORE and ITEM:
STORE ITEM
SNo SNAME AREA INO INAME Price SNo
S01 ABC Computronics GK II T01 Mother Board 12000 S01
S02 All Infortech Media CP T02 Hard Disk 5000 S01
S03 Tech Shoppe Nehru Place T03 Keyboard 500 S02
S05 Hitech Tech Store SP T04 Mouse 300 S01
T05 Mother Board 13000 S02
T06 Key Board 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard Disk 4500 S03
(A) Write the SQL queries (1 to 4):
1) To display IName and Price of all the items in the ascending order of their Price.
2) To display the SNo and SName o all stores located in CP.
3) To display the minimum and maximum price of each IName from the table Item.
4) To display the IName, price of all items and their respective SName where they are available.
(B) Write the output of the following SQL commands (1 to 4):
1) SELECT DISTINCT INAME FROM ITEM WHERE PRICE >= 5000;
2) SELECT AREA, COUNT(*) FROM STORE GROUP BY AREA;
3) SELECT COUNT(DISTINCT AREA) FROM STORE;
4) SELECT INAME, PRICE*0.05 DISCOUNT FROM ITEM WHERE SNO IN ('S02',
'S03');
www.yogeshsir.com Page: Q120/150 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Questions
9. Consider the following DEPT and WORKER tables. Write SQL queries for (i) to (iv) and find outputs for
SQL queries (v) to (viii):
Table: DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: WORKER
WNO NAME DOJ DOB GENDER DCODE
1001 George K 2013-09-02 1991-09-01 MALE D01
1002 Ryma Sen 2012-12-11 1990-12-15 FEMALE D03
1003 Mohitesh 2013-02-03 1987-09-04 MALE D05
1007 Anil Jha 2014-01-17 1984-10-19 MALE D04
1004 Manila Sahai 2012-12-09 1986-11-14 FEMALE D01
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02
1006 Jaya Priya 2014-06-09 1985-06-23 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of workers.
(i) To display Wno, Name, Gender from the table WORKER in descending order of Wno.
(ii) To display the Name of all the FEMALE workers from the table WORKER.
(iii) To display the Wno and Name of those workers from the table WORKER who are born
between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display MALE workers who have joined after ‘1986-01-01’.
(v) SELECT COUNT(*), DCODE FROM WORKER GROUP BY DCODE HAVING
COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT, CITY FROM WORKER W,DEPT D WHERE
W.DCODE=D.DCODE AND WNO<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM WORKER
10. Consider the following DEPT and EMPLOYEE tables. Write SQL queries for (i) to (iv) and find outputs
for SQL queries (v) to (viii).
Table: DEPT
DCODE DEPARTMENT LOCATION
D01 INFRASTRUCTURE DELHI
D02 MARKETING DELHI
D03 MEDIA MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: EMPLOYEE
ENO NAME DOJ DOB GENDER DCODE
1001 George K 20130902 1991-09-01 MALE D01
1002 Ryma Sen 20121211 1990-12-15 FEMALE D03
1003 Mohitesh 20130203 1987-09-04 MALE D05
1007 Anil Jha 20140117 1984-10-19 MALE D04
1004 Manila Sahai 20121209 1986-11-14 FEMALE D01
1005 R SAHAY 20131118 1987-03-31 MALE D02
1006 Jaya Priya 20140609 1985-06-23 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of employees.
(i) To display Eno, Name, Gender from the table EMPLOYEE in ascending order of Eno.
(ii) To display the Name of all the MALE employees from the table EMPLOYEE.
(iii) To display the Eno and Name of those employees from the table EMPLOYEE who are born
between '1987‐01‐01' and '1991‐12‐01'.
www.yogeshsir.com Page: Q121/150 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Questions
(iv) To count and display FEMALE employees who have joined after '1986‐01‐01'.
(v) SELECT COUNT(*),DCODE FROM EMPLOYEE
GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT FROM EMPLOYEE E, DEPT
D WHERE E.DCODE=D.DCODE AND EN0<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM EMPLOYEE;
11. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the
tables.
Table: VEHICLE
Code VTYPE PERKM
101 VOLVO BUS 160
102 AC DELUXE BUS 150
103 ORDINARY BUS 90
105 SUV 40
104 CAR 20
Note:
• PERKM is Freight Charges per kilometer
• VTYPE is Vehicle Type
Table: TRAVEL
NO NAME TDATE KM CODE NOP
101 Janish Kin 2015-11-13 200 101 32
103 Vedika sahai 2016-04-21 100 103 45
105 Tarun Ram 2016-03-23 350 102 42
102 John Fen 2016-02-13 90 102 40
107 Ahmed Khan 2015-01-10 75 104 2
104 Raveena 2015-05-28 80 105 4
106 Kripal Anya 2016-02-06 200 101 25
Note :
• NO is Traveller Number
• KM is Kilometer travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date
(i) To display NO, NAME, TDATE from the table TRAVEL in descending order of NO.
(ii) To display the NAME of all the travellers from the table TRAVEL who are travelling by
vehicle with code 101 or 102.
(iii) To display the NO and NAME of those travellers from the table TRAVEL who travelled
between ‘2015-12-31’ and ‘2015-04-01’.
(iv) To display all the details from table TRAVEL for the travellers, who have travelled
distance more than 100 KM in ascending order of NOP.
(v) SELECT COUNT (*), CODE FROM TRAVEL GROUP BY CODE HAVING
COUNT(*)>1;
(vi) SELECT DISTINCT CODE FROM TRAVEL;
(vii) SELECT A.CODE,NAME,VTYPE FROM TRAVEL A,VEHICLE B WHERE
A.CODE=B.CODE AND KM<90;
(viii) SELECT NAME,KM*PERKM FROM TRAVEL A, VEHICLE B WHERE
A.CODE=B.CODE AND A.CODE='105';
12. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the
tables.
Table: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
V02 AC DELUXE BUS 125
V03 ORDINARY BUS 80
V05 SUV 30
V04 CAR 18
16. Write the output of the queries (i) to (iv) based on the table EMPLOYEE
Table: Employee
EID Name DOB DOJ Salary Project
E01 Ranjan 1990-07-12 2015-01-21 150000 P01
E02 Akhtar 1992-06-21 2015-02-01 125000 P04
E03 Muneera 1996-11-15 2018-08-19 135000 P01
E04 Alex 1991-10-25 2018-10-19 75000 P02
E05 Satyansh 1993-12-16 2018-10-19 85000 P04
(i) SELECT NAME, PROJECT FROM EMPLOYEE ORDER BY NAME DESC;
(ii) SELECT NAME, SALARY FROM EMPLOYEE WHERE NAME LIKE 'A%';
(iii) SELECT NAME, DOJ FROM EMPLOYEE WHERE SALARY BETWEEN
100000 AND 200000;
(iv) SELECT * FROM EMPLOYEE WHERE PROJECT = 'P01';
20. Write the output of SQL queries (a) to (d) based on the table VACCINATION_DATA given below :
TABLE: VACCINATION_DATA
VID Name Age Dose1 Dose2 City
101 Jenny 27 2021-12-25 2022-01-31 Delhi
102 Harjot 55 2021-07-14 2021-10-14 Mumbai
103 Srikanth 43 2021-04-18 2021-07–20 Delhi
104 Gazala 75 2021-07-31 NULL Kolkata
105 Shiksha 32 2022-01-01 NULL Mumbai
(a) SELECT Name, Age FROM VACCINATION DATA
WHERE Dose2 IS NOT NULL AND Age > 40;
(b) SELECT City, COUNT(*) FROM VACCINATION DATA GROUP BY City;
(c) SELECT DISTINCT City FROM VACCINATION DATA;
(d) SELECT MAX (Dose1), MIN(Dose2) FROM VACCINATION DATA;
21. Write the output of SQL queries (a) and (b) based on the following two tables DOCTOR and PATIENT
belonging to the same database :
22. Write the output of the queries (i) to (iv) based on the table WORKER given below:
Table: WORKER
W_ID F_NAME L_NAME CITY STATE
102 SAHIL KHAN KANPUR UTTAR PRADESH
104 SAMEER PARIKH ROOP NAGAR PUNJAB
105 MARY JONES DELHI DELHI
106 MAHIR SHARMA SONIPAT HARYANA
107 ATHARVA BHARDWAJ DELHI DELHI
108 VEDA SHARMA KANPUR UTTAR PRADESH
i. SELECT F_NAME, CITY FROM WORKER ORDER BY STATE DESC;
ii. SELECT DISTINCT(CITY) FROM WORKER;
iii. SELECT F_NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA%';
iv. SELECT CITY, COUNT(*) FROM WORKER GROUP BY CITY;
23. Write the output of the queries (i) to (iv) based on the relations COMPUTER and SALES given below:
Table: COMPUTER
PROD_ID PROD_NAME PRICE COMPANY TYPE
P001 MOUSE 200 LOGITECH INPUT
P002 LASER PRINTER 4000 CANON OUTPUT
P003 KEYBOARD 500 LOGITECH INPUT
P004 JOYSTICK 1000 IBALL INPUT
P005 SPEAKER 1200 CREATIVE OUTPUT
P006 DESKJET PRINTER 4300 CANON OUTPUT
Table: SALES
PROD_ID QTY_SOLD QUARTER
P002 4 1
P003 2 2
P001 3 2
P004 2 1
24. Write the output of the queries (i) to (iv) based on the table GARMENT given below:
Table: GARMENT
GCODE TYPE PRICE FCODE ODR_DATE
G101 EVENINGGOWN 850 F03 2008-12-19
G102 SLACKS 750 F02 2020-10-20
G103 FROCK 1000 F01 2021-09-09
104 TULIPSKIRT 1550 F01 2021-08-10
G105 BABYTOP 1500 F02 2020-03-31
G106 FORMALPANT 1250 F01 2019-01-06
Table: CUSTOMER
CUSTID CID NAME PRICE QTY
C01 222 ROHIT SHARMA 70000 20
C02 666 DEEPIKA KUMARI 50000 10
C03 111 MOHAN KUMAR 30000 5
C04 555 RADHA MOHAN 30000 11
(i) SELECT PRODUCTNAME, COUNT(*) FROM COMPANY GROUP BY PRODUCTNAME
HAVING COUNT(*)>2;
(ii) SELECT NAME, PRICE, PRODUCTNAME FROM COMPANY C, CUSTOMER CT WHERE
C.CID=CU.CID AND C_NAME='SONY';
(iii) SELECT DISTINCT CITY FROM COMPANY;
(iv) SELECT *FROM COMPANY WHERE C_NAME LIKE'%ON%';
www.yogeshsir.com Page: Q127/150 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Questions
26. The ABC Company is considering to maintain their salespersons records using SQL to store data. As a
database administrator, Alia created the table Salesperson and also entered the data of 5 Salespersons.
Table: SALESPERSON
S_ID S_NAME AGE S_AMOUNT REGION
S001 SHYAM 35 20000 NORTH
S002 RISHABH 30 25000 EAST
S003 SUNIL 29 21000 NORTH
S004 RAHIL 39 22000 WEST
S005 AMIT 40 23000 EAST
Based on the data given above, answer the following questions:
(i) Identify the attribute that is best suited to be the Primary Key and why?
(ii) The Company has asked Alia to add another attribute in the table. What will be the new degree and
cardinality of the above table?
(iii) Write the statements to:
a) Insert details of one salesman with appropriate data.
b) Change the region of the salesman 'SHYAM' to 'SOUTH' in the table Salesperson.
c) Delete the record of salesman RISHABH, as he has left the company.
d) Remove an attribute REGION from the table.
27. Consider the table CLUB given below and write the output of the SQL queries that follow:
Table: CLUB
CID CNAME AGE GEMDER SPORTS PAY DOAPP
5246 AMRITA 35 FEMALE CHESS 900 2006-03-27
4687 SHYAM 37 MALE CRICKET 1300 2004-04-15
1245 MEENA 23 FEMALE VOLLEYBALL 1000 2007-06-18
1622 AMRIT 28 MALE KARATE 1000 2007-09-05
1256 AMINA 36 FEMALE CHESS 1100 2003-08-15
1720 MANJU 33 FEMALE KARATE 1250 2004-04-10
321 VIRAT 35 MALE CRICKET 1050 2005-04-30
Based on the given table, write SQL queries for the following:
(i) Increase the salary by 5% of personals whose allowance is known.
(ii) Display Name and Total Salary (sum of Salary and Allowance) of all personals. The column
heading ‘Total Salary’ should also be displayed.
(iii) Delete the record of personals who have salary greater than 25000
33. Consider the table Stationery given below and write the output of the SQL queries that follow:
Table: Stationery
ITEMNO ITEM DISTRIBUTOR QTY PRICE
401 Ball Pen 0.5 Reliable Stationers 100 16
402 Gel Pen Premium Classic Plastics 150 20
403 Eraser Big Clear Deals 210 10
404 Eraser Small Clear Deals 200 5
405 Sharpener Classic Classic Plastics 150 8
406 Gel Pen Classic Classic Plastics 100 15
(i) SELECT DISTRIBUTOR, SUM(QTY) FROM STATIONERY GROUP BY
DISTRIBUTOR;
(ii) SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR =
"Classic Plastics" AND PRICE > 10;
(iii) SELCET ITEM, QTY * PRICE AS "AMOUNT" FROM STATIONERY WHERE
ITEMNO = 402;
34. Consider the table Rent_cab, given below :
Table: Rent_Cab
Vcode VName Make Color Charges
101 Big car Carus White 15
102 Small car Polestar Silver 10
103 Family car Windspeed Black 20
104 Classic Studio White 30
105 Luxury Trona Red 9
Based on the given table, write SQL queries for the following :
(i) Add a primary key to a column name Vcode.
(ii) Increase the charges of all the cabs by 10%.
(iii) Delete all the cabs whose maker name is "Carus".
35. Consider the tables GAMES and PLAYERS given below:
Table: GAMES
GCode GameName Type Number PrizeMoney
101 Carrom Board Indoor 2 5000
102 Badminton Outdoor 2 12000
103 Table Tennis Indoor 4 NULL
104 Chess Indoor 2 9000
105 Lawn Tennis Outdoor 4 25000
Table: PLAYERS
PCode Name GCode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
Write SQL queries for the following :
(i) Display the game type and average number of games played in each type.
(ii) Display prize money, name of the game, and name of the players from the tables Games and
Players.
(iii) Display the types of games without repetition.
(iv) Display the name of the game and prize money of those games whose prize money is known.
36. Consider the table ORDERS as given below, and answer the questions that follow:
Table: ORDERS
O_Id C_Name Product Quantity Price
1001 Jitendra Laptop 1 12000
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
Note: The table contains many more records than shown here.
Table: COURSES
C_ID F_ID CName Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
(i) To display complete details (from both the tables) of those Faculties whose salary is less than
12000.
(ii) To display the details of courses whose fees is in the range of 20000 to 50000 (both values
included).
(iii) To increase the fees of all courses by 500 which have "Computer" in their Course names.
(iv) To display names (FName and LName) of faculty taking System Design.
(v) To display the Cartesian Product of these two tables.
• Statement 3 – to read the complete data of the query (rows whose city is Delhi) into
the object named details, from the table employee in the database.
(a) The code given below updates the records from the table Bookshop in MySQL.
• Statement 1 to form the cursor object.
• Statement 2 to execute the query that updates the Qty to 20 of the records whose
B_code is 105 in the table.
• Statement 3 to make the changes permanent in the database.
4. The code given below accepts the roll number of a student and increases the marks of that
student by 5 in the table Student. The structure of a record of table Student is:
RollNo – integer; Name – string; Clas – integer; Marks – integer
Note the following to establish connectivity between Python and MYSQL:
• Username is root
• Password is abc
• The table exists in a MYSQL database named school.
Write the following missing statements to complete the code:
Statement 1 – to open/activate the school database.
Statement 2 – to execute the command that updates the record in the table Student.
Statement 3- to make the updation in the database permanent
10. A table, named STATIONERY, in ITEMDB database, has the following structure:
Field Type
itemNo int(11)
itemName varchar(15)
price float
qty int(11)
Write the following Python function to perform the specified operation:
AddAndDisplay(): To input details of an item and store it in the table STATIONERY. The
function should then retrieve and display all records from the STATIONERY table where the
Price is greater than 120. Assume the following for Python-Database connectivity:
Username: root Password: Pencil Host: localhost
4. In which of the following switching techniques a dedicated path is established between the sender and
receiver for the entire duration of the communication.?
a) Circuit switching b) Packet switching
c) Network switching d) Physical switching
5. In which of the following switching techniques the data is divided into packets and each packet follows
its own path?
a) Circuit switching b) Packet switching
c) Network switching d) Physical switching
6. __________ is reliable but can be inefficient because the dedicated path is reserved even if no data is
being transmitted.
a) Circuit switching b) Packet switching
c) Network switching d) Physical switching
7. It's more efficient and flexible, but packets can arrive out of order or get lost, requiring retransmission
a) Circuit switching b) Packet switching
c) Network switching d) Physical switching
8. ___________ refers to the maximum rate at which data can be transmitted over a network connection
in a given amount of time.
a) Channel b) Bandwidth
c) Frequency d) Capacity
12. Which of the following wired media is the easiest to install for a LAN?
a) Coaxial Cable b) Twisted Pair Cable
c) Fiber-optic Cable d) USB Cable
13. Which of the following wired media is not recommended for economical setup of a LAN?
a) Coaxial Cable b) Twisted Pair Cable
c) Fiber-optic Cable d) USB Cable
17. Which of the following wireless media is used for very long distance communication which may cover
multiple cities or more?
a) Infrared rays b) Radio waves
c) Micro waves d) All of the above
18. Which of the following is used for short distance communication and cannot cross obstacles?
a) Infrared rays b) Radio waves
c) Micro waves d) All of the above
25. Which of the following devices can only broadcast, but cannot unicast or multicast?
a) Hub b) Switch
c) Router d) Gateway
26. A communicating device sends data to some of its connected devices. Such a communication is called
a) Broadcast b) Unicast
c) Multicast d) None of these
27. A communicating device sends data to one of its connected devices. Such a communication is called
a) Broadcast b) Unicast
c) Multicast d) None of these
28. A communicating device sends data to all of its connected devices. Such a communication is called
a) Broadcast b) Unicast
c) Multicast d) None of these
29. Which of the following devices only amplifies/regenerates the incoming signal and sends it forward?
a) Modem b) Repeater
c) Router d) Gateway
30. Which of the following devices does not know any address of any connected device?
a) Hub b) Switch
c) Router d) Gateway
31. Which of the following devices knows the MAC addresses of all the connected devices?
a) Hub b) Switch
c) Router d) Gateway
33. Which of the following devices is used to connect multiple segments of a LAN?
a) Modem b) Repeater
c) Router d) Gateway
36. Which of the following is not a valid difference between HTML and XML?
a) HTML has predefined tags, whereas XML has no predefined tags.
b) HTML is used to describe the layout of a webpage, whereas XML is used to describe the
structure of data.
c) An HTML file can be created using a text editor, whereas an XML file cannot be created
using a text editor.
d) An XML file can be interpreted by a spreadsheet package, whereas an HTML file cannot be
interpreted by a spreadsheet package.
37. __________________ is a set of rules that needs to be followed by the communicating devices in order
to have a successful and reliable data communication over a network.
a) Topology b) Media
c) Protocol d) Web Server
42. Which protocol is used to send web pages securely over a TCP/IP network?
a) PPP b) SMTP
c) FTP d) HTTPS
44. www.yogeshsir.com/home is a
a) Protocol b) Website
c) Domain Name d) URL
50. A __________is a small device that allows your computer to connect to wireless networks.
a) modem b) Wi-Fi
c) Wi-Fi card d) browser
2. Granuda Consultants are setting up a secured network for their office campus at Faridabad for their
day to day office and web based activities. They are planning to have connectivity between 3 buildings
and the head office situated in Kolkata. Answer the questions (a) to (d) after going through the building
positions in the campus and other details, which are given below:
a) Suggest the most suitable place (i.e. block) to house the server of this organization. Also give a
reason to justify your suggested location.
b) Suggest a cable layout of connections between the buildings inside the campus.
c) Suggest the placement of the following devices with justification:
(i) Switch (ii) Repeater
d) The organization is planning to provide a high speed link with its head office situated in KOLKATA
using a wired connection. Which of the following cable will be most suitable for this job?
(i) Optical Fiber (ii) Co-axial cable (iii) Ethernet cable
3. Expertia Professional Global (EPG) is an online corporate training provider company for IT related
courses. The company is setting up their new campus in Mumbai. You as a network expert have to
study the physical locations of various buildings and the number of computers to be installed. In the
planning phase, provide the best possible answers for the queries (a) to (d) raised by them.
Building to Building distances (in Mtrs.), and Number of computers in each building:
FROM - TO Distance Building No. of Computers
Administrative to Finance 60 Administrative 20
Administrative to Faculty Studio 120 Finance 40
Finance to Faculty Studio 70 Faculty Studio 120
a) Suggest the most appropriate building, where EPG should plan to install the server.
b) Suggest the most appropriate building to building cable layout to connect all three buildings
for efficient communication.
c) Which type of network out of the following is formed by connecting the computers of these
three buildings? (LAN, MAN, WAN)
d) Which wireless channel out of the following should be opted by EPG to connect to students
of all over the world? (Infrared, Microwave, Satellite)
4. Trine Tech Corporation (TTC) is a professional consultancy company. The company is planning to set
up their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand
their requirement and suggest them the best available solutions. Their queries are mentioned (a) to
(d) below.
Block to Block distances (in Mtrs.), and Number of Computers in each block:
FROM - TO Distance Block No. of Computers
Human resource to Conference 110 Human resource 25
Human resource to Finance 40 Finance 120
Conference to Finance 80 Conference 90
a) What will be the most appropriate block, where TTC should plan to install the server?
b) Draw a block to block cable layout to connect all the buildings in the most appropriate
manner for efficient communication.
c) What will be the best possible connectivity out of the following, you will suggest to connect
the new setup of offices in Bangalore with its London based office?
Satellite Link, Infrared, Ethernet cable
d) Which of the following devices will be suggested by you to connect each computer in each of
the buildings.
Switch, modem, Gateway
5. Perfect Edu Services Ltd. is an educational organization. It is planning to setup its India campus at
Chennai with its head office at Delhi. The Chennai campus has 4 main buildings – ADMIN,
ENGINEERING, BUSINESS and MEDIA
6. Uplifting Skills Hub India is a knowledge and skill community which has an aim to uplift the standard
of knowledge and skills in the society. It is planning to setup its training centers in multiple towns and
villages pan India with its head offices in the nearest cities. They have created a model of their network
with a city, a town and 3 villages as follows:
As a network consultant, you have to suggest the best network related solutions for their
issues/problems raised in (a) to (d) keeping in mind the distances between various locations and
other given parameters.
Shortest distances between, and Number of Computers at various locations:
From - To Distance Location No. of Computers
VILLAGE 1 to B_TOWN 2 KM B_TOWN 120
VILLAGE 2 to B_TOWN 1.0 KM VILLAGE 1 15
VILLAGE 3 to B_TOWN 1.5 KM VILLAGE 2 10
VILLAGE 1 to VILLAGE 2 3.5 KM VLLAGE 3 15
VILLAGE 1 to VILLAGE 3 4.5 KM A_CITY OFFICE 6
VILLAGE 2 to VILLAGE 3 2.5 KM
A_CITY Head Office to B_HUB 25 KM
Note :
• In Villages, there are community centers, in which one room has been given as
training center to this organization to install computers.
• The organization has got financial support from the government and top IT
companies.
a) Suggest the most appropriate location of the SERVER in the B_HUB (out of the 4
locations), to get the best and effective connectivity. Justify your answer.
b) Suggest the best wired medium and draw the cable layout (location to location) to
efficiently connect various locations within the B_HUB.
c) Which hardware device will you suggest to connect all the computers within each
location of B_HUB?
d) Which service/protocol will be most helpful to conduct live interactions of Experts
from Head Office and people at all locations of B_HUB?
7. Total-IT Corporation, a Karnataka based IT training company, is planning to set up training centres in
various cities in next 2 years. Their first campus is coming up in Kodagu district. At Kodagu
campus, they are planning to have 3 different blocks, one for AI, IoT and DS (Data Sciences
each). Each block has number of computers, which are required to be connected in a network
for communication, data and resource sharing. As a network consultant of this company, you have to
suggest the best network related solutions for them for issues/problems raised in question nos. (i) to
(v), keeping in mind the distances between various blocks/locations and other given parameters.
(i) Suggest the most appropriate block/location to house the SERVER in the Kodagu campus
(out of the 3 blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest a device/software to be installed in the Kodagu Campus to take care of data
security.
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to most
efficiently connect various blocks within the Kodagu Campus.
(iv) Suggest the placement of the following devices with appropriate reasons: a) Switch/Hub
b) Router
(v) Suggest a protocol that shall be needed to provide Video Conferencing solution between
Kodagu Campus and Coimbatore Campus.
8. TechnoCraft, a Chennai based IT company, is planning to set up its development center in Ariyalur
district of Tamil Nadu. At Ariyalur center, they are planning to have 3 different blocks, one each for
R&D (Research and Development), DA (Data Analytics), and AD (Application Development). Each
block will have its own computer network, and all the blocks are also needed to be inter-connected.
As a network consultant of this company, you have to suggest the best network related solutions for
them for issues/problems raised in question nos. (i) to (v), keeping in mind the distances between
various blocks/locations and other given parameters.
(i) Suggest the block to place the sever in Ariyalur center. Justify your answer.
(ii) Should the cabling be done using Twisted Pair Cable or Fiber optics cable? Give one reason
to support your answer.
(iii) Which type of network out of LAN, MAN, or WAN is formed by interconnecting all the blocks
of Ariyalur center? Justify your answer.
(iv) Do you suggest the placement of repeater anywhere in the Ariyalur center? Justify your
answer.
(v) Suggest a device/software to be installed in the Ariyalur Campus to take care of data
security.
9. FutureTech Corporation, a Bihar based IT training and development company, is planning to set up
training centers in various cities in the coming year. Their first center is coming up in Surajpur
district. At Surajpur center, they are planning to have 3 different blocks - one for Admin, one for
Training and one for Development. Each block has number of computers, which are required to
be connected in a network for communication, data and resource sharing. As a network consultant
of this company, you have to suggest the best network related solutions for them for issues/problems
raised in question nos. (i) to (v), keeping in mind the distances between various blocks/locations and
other given parameters.
Number of computers:
Block Number of Computers
Development 90
Admin 40
Training 50
(i) Suggest the most appropriate block/location to house the SERVER in the Surajpur center
(out of the 3 blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest why should a firewall be installed at the Surajpur Center?
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to most
efficiently connect various blocks within the Surajpur Center.
(iv) Suggest the placement of the following devices with appropriate reasons: a) Switch/Hub
b) Router
(v) Suggest the best possible way to provide wireless connectivity between Surajpur Center
and Raipur Center.
10. Core Study University is setting up its campus in Dubai and planning to set up a network. The
campus has 3 academic centres and one administration centre as shown in the diagram given
below:
Answers
Boolean Expressions
1. b 2. d 3. b 4. a 5. b 6. b 7. b 8. b 9. a 10. a
11. a 12. a 13. c 14. c 15. a 16. b 17. a 18. b 19. a 20. b
21. b 22. d 23. b 24. c 25. a 26. b 27. d 28. a 29. d 30. a
31. a 32. c 33. b 34. d 35. c 36. c 37. c 38. c 39. c 40. b
41. b 42. d 43. a 44. d 45. d 46. c 47. a 48. c 49. b 50. c
Lists
1. d 2. a 3. c 4. b 5. d 6. a 7. b 8. b 9. a 10. d
11. c 12. a 13. b 14. a 15. b 16. c 17. d 18. d 19. d 20. b
21. d 22. a 23. d 24. d 25. d 26. d 27. a 28. b 29. c 30. b
31. b 32. b 33. a 34. c 35. a 36. a 37. b,d 38. c,d 39. a,b 40. a,c
41. d 42. c 43. c 44. d 45. b
Tuples
1. b 2. b 3. c 4. b 5. a,d 6. b 7. d 8. a,d 9. b,d 10. c
11. b 12. a 13. a 14. c 15. c 16. a 17. c 18. a 19. d 20. b
Strings
1. b 2. b 3. c 4. c,d 5. a 6. b,d 7. b 8. d 9. a 10. b
11. a 12. d 13. d 14. a 15. b 16. c 17. d 18. c 19. d 20. b
21. c 22. d 23. c 24. b 25. a
Dictionaries
1. d 2. c 3. d 4. b 5. b,d 6. a 7. d 8. d 9. d 10. b
11. a,b,c 12. a,b 13. b 14. b 15. c 16. d 17. d 18. a 19. d 20. c
Functions
1. a 2. b 3. a,c 4. d 5. d 6. a 7. b 8. a 9. a,d 10. d
11. d 12. d 13. a 14. b,c 15. c 16. b 17. b 18. a 19. c 20. d
Text Files
1. a 2. d 3. d 4. d 5. d 6. d 7. c 8. a,b 9. a,b 10. c
11. c 12. c 13. a 14. c 15. a 16. c 17. b 18. c 19. b 20. c
21. d 22. b 23. d 24. b 25. c 26. c 27. d 28. d 29. a 30. d
31. d 32. b 33. d 34. b 35. d 36. a 37. b 38. a 39. c 40. b
CSV Files
1. b 2. a 3. d 4. d 5. d 6. d 7. a 8. c 9. b 10. a
11. a 12. a 13. b 14. b 15. b
Binary Files
1. d 2. d 3. b 4. a 5. b,c 6. a 7. a 8. b 9. b 10. a
11. d 12. c 13. a 14. a 15. a 16. b 17. c 18. a 19. c 20. c
21. b 22. d 23. c 24. a,b 25. b
Exception Handling
1. b 2. a 3. a 4. c 5. b 6. a 7. b 8. c 9. a 10. b
11. b 12. b 13. d 14. b 15. d
if..elif..else
1. Non Integer 2. No 3. B 4. 30 15 25 5. True
6. True 7. True 8. b 9. b 10. b
11. 12 12. False 13. 12 14. 6 2 20 15. 20 6 2
16. 2 22 8 17. 1 18. 12 19. -24 20. 684
21. 671 22. 000 23. Lp 24. Not Lp 25. Lp
26. Not Lp 27. Two Digit Number 28. Single Digit Number
29. Two Digit Number 30. Two Digit Number
www.yogeshsir.com Page: A3/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
Loops
1. 1-3-5-7-9-9 2. 13 9 5 6 3. 0:1:2:7
4. 0:1:2:3:4:11 5. 46567 and 4656 and 6. 1 2 3 -
11 5 6 7 i.9
7. 10 1;16 7;25 7;34 7; 8. 2.0 9. 3.5
10 5 72
10. 469 2 11. 7 $ 12. 1 3
6$ 24
# 35
465 46
57
6 --
13. 0:3&3-3 14. 4--8--11 15. -4--0--3
1:5&5-5
2:7&7-7
7
Lists
1. 73291 2. 4 3. cat
[1, 2, 3] ['ant', 'bat']
[4, 5, 6] ['cat', 'dog', 'eel']
[1, 4] ['eel', 'bat']
4. [8, 6] 5. 2 3 2 3 2 6. 10 11 20
[6, 33, 12, 8, 6]
[8, 23]
[]
7. 526 8. 3 16 64 9. 5#-8#4
10. 6 None 4 11. [1, 2, 'a', 'b'] 12. 1, 2, ['a', 'b']]
13. [1, 2, 3, 4, ['a', 'b']] 14. [1, 2, 3, 4, 'a', 'b'] 15. [1, 2, 'a'] [1, 2, 'a'] [1, 2]
16. 6 17. [1, 2, 3, 3, 4] None 18. [5, 3, 4]
19. 3 20. 31 21. [15, 29, 56, 109, 214]
22. [0, 0, 0, 8, 2, 0, 2, 6, 4] 23. [67, 67, 67, 67, 67, 67] 24. 88
25. 89 59
Tuples
1. 732 2. 4 3. 765
(1, 2, 3)
(4, 5, 6)
(1, 4)
4. 3#[1]#5 5. 1 6. (1, 2, 'a', 'b')
[2, 3, 4, 5, 6]
[2, 3, 4, 5, 6]
7. (1, 2, 3) (1, 2) 8. (1, 2, 3) 9. 3
((1, 2),)
Strings
1. 7:S:t 2. The Quiz 3. P:s:o:i
(Strings)
18:
:z
4. Na 5. 3333 6. 3444
io
al
9
7. -*-*-*-*-*-*-*-* 8. tional*Na*Ntoa 9. al#Nation#lnia
10. onal:a:Nt 11. 2-4-0-10 12. 1-3-3
13. ['a', 'and', 'b', 'and', 'c'] 14. ['a ', ' b\n', ' c'] 15. ['', ' ', 'nd b']
16. ['', ''] 17. ['a and b'] 18. Vision
19. V,i,s,i,o,n 20. 1 and 2 and 3 21. a*b*c
11 13 5
22. ('Inte', 'r', 'national') 23. ('In', 't', 'ernational') 24. ('I', 'n', 'ternational')
25. ('Inter', 'na', 'tional') 26. ('', 'I', 'nternational') 27. ('Internation', 'al', '')
28. ('International', '', '') 29. ('', 'Pen', ' and Pencil') 30. Writer writes
31. Writer writes 32. their weird foreign 33. their weird foriegn
Writer reads freinds friends
34. 1, 10 35. 8, 8 36. 9, 17
37. -1, -1 38. Live and let live 39. q fOR qUIZ
40. A-n-t
Dictionaries
1. [1, 3] 2. [1, 3]
3. [2, 4] 4. [(1, 2), (3, 4)]
5. {1: None, 2: None, 3: None} 6. {1: 'a', 2: 'a', 3: 'a'}
7. {'a': [1, 2, 3]} 8. {'a': 'app', 'p': 'app'}
9. {1: None, 2: None} 10. {1: None, 2: None}
11. {'One': None, 'Two': None} 12. {(1, 'One'): None, (2, 'Two'): None}
13. {} 14. Two
Two
15. None 16. Two
Three Two
None
None
{1: 'One', 2: 'Two', 3: None}
17. Three 18. Two
Three -
{1: 'One', 2: 'Two', 3: 'Three'}
www.yogeshsir.com Page: A5/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
Functions
1. 10 20 2. 10 20 3. 12 10
4. 12 10 5. 10 12 6. 4 5 6
7. 6 12 5 8. 5 1 6 9. Hello
None
10. Hello 11. Hi 12. Done
Hi None
13. HiBye 14. 10 15. 18
11
7
(8, 7)
16. [1, 2, 'H', 'i'] 17. 10 18. [1, 3, 5]
19. [6, 31, 0, 3, 0] 20. (4, 10, 14, 16, 4)
2.
(i) input("Enter a number:")
(ii) input("Enter your age: ") #No Error
(iii) int(56) #No error
(iv) int("56.6") -> int(56.6) #Remove quotation marks
(v) int("fifty6") -> int('56')
(vi) int('56')
(vii) int(56)
3.
(i) n1,n2=5,4
if n1==n2:
print("Equal")
(ii) n1=n2=12/5
if n1!=n2:
print("Not equal") #indent
else: print("Equal")
(iii) age=12
if age<=10:
print("Primary")
elif age<=13:
print("Middle")
elif age<=15:
print("Secondary")
elif age<=17:
print("Sr Secondary")
(v) a=b=c=12,13,14
if (a>=b or a<=c and a+c<=b):
print("A") #Indentation
else: print(a+b+c)
4.
(i) a=int(input("Enter a number: "))
c=1
for b in range (a,a*10,a):
c*=b
print(a,b,c)
(vi) x=123045
while x%10:
d=x%10
for i in range(d):
print(i)
else: print (d) #deindent
print(x,sep='--')
x//=10
else: print(x)
(vii) n=100; s=0 #OR Write the two statements in separate lines.
for i in range(1,n+1):
if n%i==0:
s+=i
else: n+=1
print(n,s)#
www.yogeshsir.com Page: A8/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
(viii) a=10
while a>=0:
if a%2==0:
print(a)
else:
print(a//2) #Indentation
a-=1
(ix) d1=dict.fromkeys('banana')
d2=dict.fromkeys('pineapple','apple')
d1.update(d2)
for k in d1.keys():
if k in d2:
print(d2[k], end=' ')
else: print(d1[k])
(x) voter = {'name': "Alok", 'age': 30, 'city': "Agra"}
print(voter["name"])
voter["country"] = "India"
del voter["age"]
(xi) To=30
for K in range(0,To):
if K%4==0:
print (K*4)
else:
print (K+3)
5.
(i) a=[1,2,3,2,1]
for x in range(a):
print(x)
(ii) a=["Umang","Usman","Utkarsh","Umedh"]
for x in range(len(a)):
print(a[x])
29. T1=tuple(L1)
30. T2=T1+tuple(L2)
31. print(len(S1))
32. print(len(S2.split()))
33. print(S1.upper())
34. print(S1.lower())
35. print(S1.capitalize())
36. print(S1.title())
37. print(S1.index(ch))
38. print(S1.find(ch))
39. print(S3.lstrip())
40. print(S3.rstrip())
41. print(S3.strip())
42. print(S4.split())
43. sorted(S1)
44. sorted(S2,reverse=True)
45. high,low=max(S1),min(S2)
46. T3=() #or t3=TUPLE()
47. T4=tuple('Campground')
48. T5=T1[:3]+T2[-3:]
49. print(len(T2))
50. print(len(T1+T2)) #OR print(len(T1+T2))
51. T1=T1+(T2,)
52. T1=T1+T2 #OR T1+=T2
53. T1=T1[:3]+(T2,)+T1[3:]
54. T1.count('e')
55. T2.count(T1[3])
56. print(T2.index('s'))
57. print(T2.index('s',T2.index('s')+1))
58. L1=sorted(T1)
59. print(min(T1),max(T1))
60. print(sum(T1))
73. print(D2.popitem()[1])
74. print(D2.get(k))
75. print(D2.setdefault(k,'Kite'))
76. print(sorted(D1.keys()))
77. print(sorted(D2.values()))
78. print(D1[max(D1)])
79. print(D2[min(D2)])
80. D2.update(D1)
7. def Alternate(nums):
n=len(nums)
if n%2==1:
n-=1
for i in range(0,n,2):
nums[i],nums[i+1]=nums[i+1],nums[i]
print(nums)
8. def combine(A,B,C):
n=len(A)
for i in range(n):
x=2*A[i]+3*B[i]
C.append(x)
9. def calculate(A):
n=len(A)
for i in range(n):
if A[i]%5==0:
A[i]//=5
else: A[i]*=2
10. def combine(A,B,C):
n=len(A)
for i in range(n):
C.append(A[i])
C.append(B[i])
11. def replace(A):
n=len(A)
for i in range(n):
if A[i]%2==0:
A[i]//=2
else: A[i]*=2
12. def shortName(ft,md,last):
nm=ft[0]+'. '+md[0]+'. '+last
return nm
13. def palin(S):
if S.upper()==S[::-1].upper():
print('Palindrome')
else: print('Not Palindrome')
14. def countPalin(n):
c=0
for i in range(n):
S=input("Enter a string: ")
if S==S[::-1]:
c+=1
return c
6. def show(n):
with open("MIRA.TXT") as f:
data = f.read()
data=data.replace('\n','')
if n<=len(data):
print(data[n-1])
else: print('Invalid n')
7. def memy():
with open("DIARY.TXT") as f:
data = f.read()
data=data.upper()
words=data.split()
c=words.count('ME')+words.count('MY')
print("Count of Me/My in file:",c)
8. def Places():
with open("Places.TXT") as f:
for line in f:
if line[0] in 'PS':
print(line.rstrip())
9. def CountHisHer():
with open("Gender.TXT") as f:
data=f.read()
data=data.upper()
words=data.split()
his=words.count('HIS')
her=words.count('HER')
print('Count of His:',his)
print('Count of Her:',her)
10. def EUCount():
with open("IMP.TXT") as f:
data=f.read()
data=data.upper()
e=data.count('E')
u=data.count('U')
print('E:',e)
print('U:',u)
11. def SUCCESS():
with open("STORY.TXT") as f:
data=f.read()
data=data.upper()
words=data.split()
s=words.count('SUCCESS')
s+=words.count('SUCCESS,')
s+=words.count('SUCCESS.')
print(s)
1. import csv
def Append():
F_id=input("Enter furniture ID: ")
desc=input("Enter Description: ")
pr=int(input("Enter Price: "))
disc=float(input("Enter discount: "))
rec=[F_id, desc, pr, disc]
with open("Furniture.csv",'a',newline='') as f:
w=csv.writer(f)
w.writerow(rec)
def countRec():
with open('furniture.csv') as f:
r=csv.reader(f)
c=0
for rec in r:
if int(rec[2])<5000:
c+=1
print(c,'records')
Append()
countRec()
2. import csv
def ADD():
E_id=input("Enter Emplyee ID: ")
name=input("Enter Name: ")
mob=int(input("Enter Mobile Number: "))
rec=[E_id, name, mob]
with open("record.csv",'a',newline='') as f:
w=csv.writer(f)
w.writerow(rec)
def COUNTREC():
with open('record.csv') as f:
r=csv.reader(f)
data=list(r)
print(len(data),'records')
ADD()
COUNTREC()
3. import csv
def addCust():
with open("cust.csv",'a',newline='') as f:
w=csv.writer(f,delimiter='*')
recs=[['001','Nihir',8000],
['104','Akshay',5000]]
w.writerows(recs)
def readCust():
with open('cust.csv') as f:
r=csv.reader(f, delimiter='*')
for rec in r:
print(rec)
addCust()
readCust()
4. import csv
def getInventory():
with open("Inventory.csv",'a',newline='') as f:
w=csv.writer(f)
cd=input("Enter inventory code: ")
nm=input("Enter inventory name: ")
pr=input("Enter inventory price: ")
reorder=input("Enter reorder: ")
rec=[cd,nm,pr,reorder]
w.writerow(rec)
def Search(code):
with open('Inventory.csv') as f:
r=csv.reader(f)
found=0
for rec in r:
if rec[0]==code:
print(rec)
found=True
break
if found==False:
print('Record not found')
getInventory()
Search('5')
5. import csv
def add():
with open("furdata.csv",'a',newline='') as f:
w=csv.writer(f)
fid=input("Enter furniture code: ")
fname=input("Enter furniture name: ")
fprice=input("Enter furniture price: ")
rec=[fid,fname,fprice]
w.writerow(rec)
def search():
with open('furdata.csv') as f:
r=csv.reader(f)
found=0
for rec in r:
if int(rec[-1])>10000:
print(rec)
found=1
if found==0:
print("No item with price more than 10000")
add()
search()
6. Statement 1: a
Statement 2: csv.writer(csvf)
Statement 3: csv.writerow(['Title','Author','Price'])
Statement 4: csv.reader(csvf)
Statement 5: r[0][0]=='K'
7. Statement-1: csv
Statement-2: 'student.csv','w'
Statement-3: writer(fh)
Statement-4: roll_no, name, Class, section
Statement-5: writerows()
8. Statement 1: import csv
Statement 2: csvwriter.writerows(data)
Statement 3: next(csvreader)
Statement 4: csvreader
9. Line 1: csv
Line 2: 'a'
Line 3: reader
Line 4: ['Arjun', '123@456']
['Arunima', 'aru@nima']
['Frieda', 'myname@FRD']
3. import pickle
def search(b):
with open('BOOK.DAT','rb') as f:
found=0
try:
while True:
rec=pickle.load(f)
if rec["BookNo"]==b:
print(rec)
found=1
except EOFError:
if found==0:
print("Book not found")
4. import pickle
def search():
with open('VINTAGE.DAT','rb') as f:
found=0
try:
while True:
rec=pickle.load(f)
if 200000<rec[-1]<250000:
print(rec)
found=1
except EOFError:
if found==0:
print("No such vehicle found")
5. import pickle
def AddRec():
with open("LAPTOP.DAT",'ab') as f:
mdl=int(input("Enter Model Number: "))
ram=int(input("Enter RAM: "))
hdd=int(input("Enter HDD: "))
det=input("Enter details: ")
rec=[mdl,ram,hdd,det]
pickle.dump(rec,f)
def Search():
with open('LAPTOP.DAT','rb') as f:
mdl=int(input("Enter model number to search for: "))
found=0
try:
while True:
rec=pickle.load(f)
if rec[0]==mdl:
print(rec)
found=1
except EOFError:
if found==0:
print("No such Laptop found")
6. import pickle
def AddRec():
with open("MIC.DAT",'ab') as f:
code=input("Enter Code: ")
br=input("Enter Brand: ")
tp=input("Enter Type: ")
pr=int(input("Enter Price: "))
rec={code:[br,tp,pr]}
pickle.dump(rec,f)
def ShowBT():
with open('MIC.DAT','rb') as f:
c=0
try:
while True:
rec=pickle.load(f)
for k,v in rec.items():
if v[1]=='BT':
print(rec)
c+=1
except EOFError:
print(c,"Records")
7. import pickle
def ShowDetails():
with open('GAMES.DAT','rb') as f:
c=0
try:
while True:
rec=pickle.load(f)
if rec[-1]=="8 to 13":
print(rec)
except EOFError:
pass
8. import pickle
def SALE():
with open('GIFT.DAT','rb') as f:
data=[]
try:
while True:
rec=pickle.load(f)
for k,v in rec.items():
v[1]='ON SALE'
v[2]=v[2]*50/100
rec[k]=v
data.append(rec)
except EOFError:
pass
with open('GIFTS.DAT','wb') as f:
for rec in data:
pickle.dump(rec,f)
9. import pickle
def BUMPER():
with open('GIFT.DAT','rb') as f:
try:
while True:
rec=pickle.load(f)
if rec[2]=='ON SALE':
print(rec)
except:
pass
10. import pickle
def Update():
with open('LAPTOP.DAT','rb') as f:
data=[]
try:
while True:
rec=pickle.load(f)
if rec[2]>=1024:
rec[1]=16
data.append(rec)
except EOFError:
pass
with open('LAPTOP.DAT','wb') as f:
for rec in data:
pickle.dump(rec,f)
11. import pickle
def Update():
import pickle
from os import remove, rename
with open('BOOK.DAT','rb') as f1:
with open('TEMP.DAT','wb') as f2:
try:
while True:
rec=pickle.load(f1)
print(rec)
edition=int(input("Enter Edition: "))
rec['Edition']=edition
pickle.dump(rec,f2)
except EOFError:
f1.close()
f2.close()
remove('BOOK.DAT')
rename('TEMP.DAT','BOOK.DAT')
Answers - Stacks
1. A stack is a linear data structure which facilitates LIFO type of data processing.
A stack should be implemented using a list to allow for insertion and deletion, and it is allowed in a list and not
in a tuple.
2. PUSH inserts an element at the top of a stack.
POP deletes the topmost element of the stack.
3. Characteristics of Stacks:
(i) It is a LIFO data structure
(ii) The insertion and deletion happens at one end i.e. from the top of the stack
4. LIFO – Last In First Out
Stack facilitates LIFO operations.
5. s=[] #stack
def PushKeys(R):
for k, v in R.items():
if v>75:
s.append(k)
def PopKeys():
while s:
print(s.pop(),end=" ")
R={"OM":76, "JAI":45, "BOB":89,"ALI":65, "ANU":90, "TOM":82}
PushKeys(R)
PopKeys()
6. s=[] #stack
def PUSH(N):
for num in N:
if num%2==0:
s.append(num)
def POP():
while s!=[]:
print(s.pop(),end=" ")
N=[12,13,34,56,21,79,98,22,35,38]
PUSH(N)
POP()
7. s=[] #stack
def PUSH(Herbs):
for k,v in Herbs.items():
if v[0]=='G':
s.append((k,v))
def POP():
while s:
print(s.pop(),end=" ")
Herbs={'Adrak':'Ginger', 'Amla': 'Gooseberry', 'Babool': 'Indian Gum',
'Dhania': 'Coriander', 'Lahsun':'Garlic', 'Tulsi': 'Basil'}
PUSH(Herbs)
POP()
8. s=[] #stack
def PUSH(s, ele):
s.append(ele)
def POP(s):
if s==[]: print('Underflow. Stack is empty')
9. s=[] #stack
from random import randint
nums=[randint(10,99) for I in range(20)]
def PUSH(N):
for n in N:
if n%2==0: s.append(n)
for n in N:
if n%2!=0: s.append(n)
def POP():
while s:
print(s.pop(),end=' ')
PUSH(nums)
POP()
10.
After POP(S) After POP(S) After PUSH(S,8)
5 TOP 8 TOP
9 9 TOP 9
2 2 2
3 TOP 9 TOP
8 8 TOP 8
9 9 9
2 2 2
11.
None
10
b
5 6
2
12.
After PUSH(S,8) After POP(S) After PUSH(S,3)
8 TOP 3 TOP
9 9 TOP 9
5 5 5
9 9 9
2 2 2
9 TOP 9 TOP
5 5 TOP 5
9 9 9
2 2 2
13.
status=[] #stack
def Push_element(cust):
if cust[2]=="Goa":
L1=[cust[0],cust[1]]
status.append(L1)
def Pop_element ():
while status:
dele=status.pop()
print(status.pop(), end=' ')
print("Stack Empty")
14.
stackItem=[] #stack
def Push(SItem):
for k,v in SItem.items():
if (v>75):
stackItem.append(k)
print("The count of elements in the stack is : ", len(stackItem))
Used for fixed length strings Used for variable length strings
Max limit of char is less than that of varchar Max limit of varchar is more than that of char
13. A table may have one or more than one such attribute/group of attributes that identify a row/tuple uniquely. All
such attribute(s)/group(s) are known as Candidate keys. Out of the candidate keys, one is selected as primary
key.
Example:
Relation: EMP
ENO Name Sal Dept Email
1 Rajat 50000 SALES [email protected]
2 Sumit 60000 ADMIN [email protected]
3 Aleena 55000 SALES [email protected]
In this relation ENO and Email are Candidate keys. Any one of these can be designated as the Primary key.
14. UNIQUE
15. NOT NULL
16. ALTER TABLE MOBILE DROP PRIMARY KEY;
17. ALTER TABLE MOBILE ADD PRIMARY KEY (M_ID);
18. HAVING is used for including conditions based on aggregate functions on groups.
SELECT DEPT, COUNT(*) FROM EMPLOYEE GROUP BY DEPT HAVING COUNT(*)>1;
Above command will return the number of employees in each department for the departments having more than
1 employee.
19. Degree of a table is the number of columns (attributes) in It, whereas Cardinality is the number of rows (tuples)
in it.
Degree of the given table is 3 and its Cardinality is 2.
20. A table may have one or more than one such attribute/group of attributes that identify a row/tuple uniquely. All
such attribute(s)/group(s) are known as Candidate keys. Out of the candidate keys, one is selected as primary
key and the other candidate keys are known an alternate keys.
Example:
Relation: EMP
ENO Name Sal Dept Email
1 Rajat 50000 SALES [email protected]
2 Sumit 60000 ADMIN [email protected]
3 Aleena 55000 SALES [email protected]
In this relation ENO and Email are Candidate keys. If ENO is selected as the primary key, then Email will be
the alternate key, and vice-versa.
4. desc stdmaster;
5. drop table stdmaster
6. create table stdmaster
(AdmNo char(10), admdate date, name varchar(20),
email varchar(30), class int(2), section char(1), rno int(2));
7. alter table stdmaster add primary key (admno);
8. alter table stdmaster add unique(email);
9. alter table stdmaster change name name varchar(20) not null;
10. (i) insert into stdmaster values('200700001','2007-04-01',
'Abhay','[email protected]',1,'A',1);
(ii) insert into stdmaster values('200700002','2007-04-01',
'Azhar','[email protected]',1,'A',2);
(iii) insert into stdmaster values('200800012','2008-06-13',
'Bharat','[email protected]',5,'B',6);
(iv) insert into stdmaster values('200800007','2008-04-11',
'Sukhdeep','[email protected]',3,'B',11);
(v) insert into stdmaster values('200800009','2008-04-13',
'Benita','[email protected]',3,'C',4);
11. select * from stdmaster;
12. insert into stdmaster values('200800009','2008-04-13',
'Benita','[email protected]',3,'C',4);
13. insert into stdmaster (admno) values('200900012');
14. select * from stdmaster order by class;
15. select * from stdmaster order by class desc;
16. select * from stdmaster order by class, name;
17. select * from stdmaster order by class desc, name;
18. select * from stdmaster where class=1;
19. select * from stdmaster where class>1;
20. select * from stdmaster where class >1 and section='B';
21. select * from stdmaster where class in (1,5);
22. select * from stdmaster where class not in (1,5);
23. select * from stdmaster where not class in (1,3);
24. select distinct class from stdmaster;
25. select * from stdmaster where email is null;
26. select * from stdmaster where email is not null;
27. select admno, admdate, email from stdmaster where name like 'A%';
28. select name from stdmaster where name not like '%a';
29. select * from stdmaster where section between 'B' and 'C';
30. alter table stdmaster add fee float;
31. update stdmaster set fee=class*100;
32. select admno, fee, fee*0.05 as scholarship from stdmaster;
33. select max(fee),min(fee),avg(fee),count(fee),sum(fee) from stdmaster;
34. select max(fee),min(fee),avg(fee),count(fee),sum(fee) from stdmaster where
class=5;
35. select min(fee)*2 as "Lowest Sch", max(fee)*2 as "Highest Sch" from
stdmaster;
36. select section, count(section) from stdmaster group by section;
37. select section, count(section) from stdmaster group by section having
count(section)>1;
38. select section, count(section) from stdmaster where name like 'A%' group
by section;
39. select section, count(section) from stdmaster where name like 'A%' group
by section having count(section)>2;
40. create table HouseAct
(admno char(10), house varchar(10) not null, activity varchar(20),
foreign key (admno) references stdmaster(admno));
www.yogeshsir.com Page: A33/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
(iii) (iv)
Name Pay PLEVEL PAY+ALLOWANCE
Radhey Shyam 26000 P003 18000
Chander Nath 12000
6.
(A)
1) SELECT VehicleName FROM CARHUB WHERE Color = 'WHITE';
2) SELECT VehicleName, Make, Capacity FROM CARHUB ORDER BY CAPACITY;
3) SELECT MAX(Charges) FROM CARHUB;
4) SELECT CName, VehicleName, FROM CUSTOMER, CARHUB
WHERE CUSTOMER.Vcode = CARHUB.Vcode;
(B)
1) 2)
COUNT(DISTINCT Make) MAX(Charges) MIN(Charges)
4 35 12
3) 4)
COUNT(*) VehicleName
5 SX4
C Class
www.yogeshsir.com Page: A35/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
7.
a) SELECT * FROM ITEMS ORDER BY INAME;
b) SELECT INAME, PRICE FROM ITEMS WHERE PRICE BETWEEN 10000 AND 22000;
c) SELECT TCODE, COUNT(*) FROM ITEMS GROUP BY TCODE;
d) SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY > 150;
e) SELECT INAME FROM TRADERS WHERE CITY IN ('DELHI', 'MUMBAI');
f) SELECT COMPANY, INAME FROM ITEMS ORDER BY COMPANY DESC;
g1) g2)
MAX(PRICE) MIN(PRICE) AMOUNT
38000 1200 1075000
g3) g4)
DISTINCT TCODE INAME TNAME
T01 LED SCREEN 40 DISP HOUSE INC
T02 CAR GPS SYSTEM ELECTRONIC SALES
T03
8.
(A)
1) SELECT IName, price from Item ORDER BY Price;
2) SELECT SNo, SName FROM Store WHERE Area='CP';
3) SELECT IName, MIN(Price), MAX(Price) FROM Item GROUP BY IName;
4) SELECT IName, Price, SName FROM Item, Store Where Item.SNo =
Store.SNo;
(B)
1) 2)
DISTINCT INAME Area Count(*)
Hard disk CP 2
LCD GK II 1
Mother Board Nehru Place 2
3) 4)
COUNT(DISTINCT AREA) INAME DISCOUNT
3 Keyboard 25
Mother Board 650
Hard Disk 225
9.
(i) SELECT Wno, Name, Gender FROM Worker ORDER BY Wno DESC;
(ii) SELECT Name FROM Worker WHERE Gender='FEMALE';
(iii) SELECT Wno, Name FROM Worker
WHERE DOB BETWEEN '19870101' AND '1991-12-01';
OR
SELECT Wno, Name FROM Worker
WHERE DOB >='1987-01-01' AND DOB <='1991-12-01'
(iv) SELECT COUNT(*) FROM Worker
WHERE GENDER='MALE' AND DOJ > '1986-01-01';
(v) (vi)
COUNT(*) DCODE Department
2 D01 MEDIA
2 D05 MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
(vii) (viii)
NAME DEPARTMENT CITY MAX(DOJ) MIN(DOB)
George K MEDIA DELHI 2014-06-09 1984-10-19
Ryma Sen INFRASTRUCTURE MUMBAI
10.
(i) SELECT Eno,Name,Gender FROM Employee ORDER BY Eno;
(ii) SELECT Name FROM Employee WHERE Gender='MALE';
(iii) SELECT Eno,Name FROM Employee
WHERE DOB BETWEEN '19870101' AND '1991-12-01';
OR
SELECT Eno,Name FROM Employee
WHERE DOB >='1987-01-01' AND DOB <='1991-12-01';
OR
SELECT Eno,Name FROM Employee
WHERE DOB >'19870101' AND DOB <'1991-12-01';
(vii) (viii)
NAME DEPARTMENT MAX(DOJ) MIN(DOB)
George K INFRASTRUCTURE 2014-06-09 1984-10-19
Ryma Sen MEDIA
11.
(i) SELECT NO, NAME, TDATE FROM TRAVEL ORDER BY NO DESC;
(ii) SELECT NAME FROM TRAVEL
WHERE CODE=101 OR CODE=102;
(iii) SELECT NO, NAME from TRAVEL
WHERE TDATE BETWEEN '2015-04-01' AND '2015-12-31';
(iv) SELECT * FROM TRAVEL WHERE KM > 100 ORDER BY NOP;
(v) (vi)
COUNT(*) CODE DISTINCT CODE
2 101 101
2 102 102
103
104
105
(vii) (viii)
CODE NAME VTYPE NAME KM*PERKM
104 Ahmed Khan CAR Raveena 3200
Ryma Sen Raveena SUV
12.
(i) SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;
(v) (vi)
COUNT(*) VCODE DISTINCT(VCODE)
2 V01 V01
2 V02 V02
V03
V04
V05
(vii) (viii)
VCODE CNAME VEHICLETYPE CNAME KM*PERKM
V02 Ravi Anish AC DELUXE BUS Sahanubhuti 2700
V04 John Malina CAR
13.
(i) (ii)
MIN(PRICE) MAX(PRICE) COMPANY COUNT(*)
200 4300 LOGITECH 2
CANON 2
(iii) (iv)
PROD_NAME QTY_SOLD PROD_NAME COMPANY QUARTER
MOUSE 3 MOUSE LOGITECH 2
KEYBOARD 2 LASER PRINTER CANON 1
JOYSTICK 2 KEYBOARD LOGITECH 2
JOYSTICK IBALL 1
14.
(A)
a) LABNO, LAB_NAME
b) Degree: 5, Cardinality: 5
(B)
a) INSERT INTO LAB VALUES('L006','PHYSICS','RAVI',25,'II');
b) UPDATE LAB SET CAPACITY=CAPACITY+10 WHERE FLOOR='I';
c) ALTER TABLE LAB ADD PRIMARY KEY (LABNO);
d) DROP TABLE LAB;
15.
CODE BNAME TYPE MNO MNAME ISSUEDATE
L102 Easy Python Programming M101 SNEH SINHA 2022-10-13
C101 Juman Ji Thriller M102 SARA KHAN 2022-06-12
F102 Untold Story Fiction M103 SARTHAK 2021-02-23
16.
(i) (ii) (iii)
Name Project Name Salary Name DOJ
Satyansh P04 Akhtar 125000 Ranjan 2015-01-21
Ranjan P01 Alex 75000 Akhtar 2015-02-01
Muneera P01 Muneera 2018-08-19
Alex P02
Akhtar P04
(iv)
EID Name DOB DOJ Salary Project
E01 Ranjan 1990-07-12 2015-01-21 150000 P01
E03 Muneera 1996-11-15 2018-08-19 135000 P01
17.
(i) (ii)
FID MIN(FEES) MAX(FEES) AVG(SALARY)
F01 12000 40000 29500
F03 8000 8000
F04 15000 17000
F05 NULL NULL
(iii) (iv)
FNAME CNAME FNAME CNAME FEES
Neha Python Anishma Grid Computing 40000
Neha Computer Network Neha Python 17000
18.
(i) ADNO, ROLLNO
(ii) Degree: 8, Cardinality: 4
(iii) UPDATE RESULT SET SEM2=SEM2+3/100*SEM2 WHERE SEM2 BETWEEN 70 AND 100;
19.
(i) SNo, as it cannot have same value for multiple records.
(ii) Degree: 8, Cardinality: 7
(iii)
a) alter table Studios add column Founder varchar(20);
b) delete from studios where name='R K Films';
c) ALTER TABLE STUDIOS ADD PRIMARY KEY (SNO);
d) UPDATE STUDIOS SET FOUNDED=2000 WHERE NAME='ASHIRWAD CINEMAS';
20.
(a) (b) (c) (d)
Name Age City Count(*) City Max(Dose1) Min(Dose2)
Harjot 55 Delhi 2 Delhi 2022-01-01 2021-07-20
Srikanth 43 Mumbai 2 Mumbai
Kolkata 1 Kolkata
21.
(a) (b)
DNAME PNAME PNAME ADMDATE FEES
AMITABH NOOR NOOR 2021-12-25 1500
ANIKET ANNI HARMEET 2019-12-20 1500
AMITABH HARMEET
22.
(a) (b)
F_NAME CITY CITY
SAHIL KANPUR KANPUR
VEDA KANPUR ROOP NAGAR
SAMEER ROOP NAGAR DELHI
MAHIR SONIPAT SONIPAT
MARY DELHI
ATHARVA DELHI
(c) (d)
F_NAME STATE CITY COUNT(*)
SAHIL UTTAR PRADESH KANPUR 2
MAHIR HARYANA ROOP NAGAR 1
ATHARVA DELHI DELHI 2
VEDA UTTAR PRADESH SONIPAT 1
23.
(i) (ii)
MIN(PRICE) MAX(PRICE) COMPANY COUNT(*)
200 4300 LOGITECH 2
CANON 2
(iii) (iv)
PROD_NAME QTY_SOLD PROD_NAME COMPANY QUARTER
MOUSE 3 MOUSE LOGITECH 2
KEYBOARD 2 LASER PRINTER CANON 1
JOYSTICK 2 KEYBOARD LOGITECH 2
JOYSTICK IBALL 1
24.
(i) (ii)
DISTINCT(COUNT(FCODE)) FCODE COUNT(*) MIN(PRICE)
3 F02 2 750
F01 3 1000
(iii) (iv)
TYPE GCODE TYPE PRICE FCODE ODR_DATE
FROCK G103 FROCK 1000 F01 2021-09-09
G106 FORMAL PANT 1250 F01 2019-01-06
25.
(i) (ii)
PRODUCTNAME COUNT(*) NAME PRICE PRODUCTNAME
MOBILE 3 MOHAN KUMAR 30000 TV
(iii) (iv)
DISTINCT(CITY) CID C_NAME CITY PRODUCTNAME
DELHI 111 SONY DELHI TV
MUMBAI 333 ONIDA DELHI TV
CHENNAI 444 SONY MUMBAI MOBILE
26.
(i) Primary key: S_ID
As it is non-repeating value and not expected to repeat for new rows too.
(ii) Degree = 6 and Cardinality = 5
(iii)
(a) INSERT INTO SALESPERSON VALUES ("S006","JAYA",23,34000,'SOUTH');
(b) UPDATE SALESPERSON SET REGION='SOUTH' WHERE S_NAME="SHYAM";
(a) DELETE FROM SALESPERSON WHERE S_NAME="RISHABH";
(b) ALTER TABLE SALESPERSON DROP COLUMN REGION;
27.
(i) (ii) (iii)
COUNT(DISTINCT(SPORTS)) CNAME SPORTS CNAME AGE PAY
4 AMINA CHESS AMRIT 28 1000
VIRAT 35 1050
www.yogeshsir.com Page: A40/52 www.youtube.com/LearnWithYK
QB/XII/CS-083/2025/YK/Answers
28.
(i) UPDATE Personal SET Salary=Salary + Salary*0.5
WHERE Allowance IS NOT NULL;
(ii) SELECT Name, Salary + Allowance AS "Total Salary" FROM Personal;
(iii) DELETE FROM Personal WHERE Salary>25000
29.
(i) SELECT PName, BName FROM PRODUCT P, BRAND B WHERE P.BID=B.BID;
(ii) DESC PRODUCT;
(iii) SELECT BName, AVG(Rating) FROM PRODUCT P, BRAND B WHERE P.BID=B.BID
GROUP BY BName HAVING BName='Medimix' OR BName='Dove';
(iv) SELECT PName, UPrice, Rating FROM PRODUCT ORDER BY Rating DESC;
30.
(i) (ii) (iii)
ITEM SUM(QTY) ITEM QTY ORDNO ORDATE
RICE 48 RICE 25 1004 2023-12-25
PULSES 29 WHEAT 28 1007 2024-04-30
WHEAT 80
31.
(i) ALTER TABLE Projects ADD PRIMARY KEY (P_id);
(ii) UPDATE Projects SET LANGUAGE= "Python" WHERE P_id = "P002";
(iii) DROP TABLE Projects;
32.
(i) SELECT S_name, Stop_name FROM Admin, Transport
WHERE Admin.S_id = Transport.S_id;
(ii) SELECT COUNT(*) FROM Admin WHERE S_type IS NULL;
(iii) SELECT * FROM Admin WHERE S_name LIKE 'V%';
(iv) SELECT S_id, Address FROM Admin ORDER BY S_name;
33.
(i) (ii)
DISTRIBUTOR SUM(QTY) ITEMNO ITEM
Reliable Stationers 100 402 Gel Pen Premium
Classic Plastics 400 406 Gel Pen Classic
Clear Deals 410
(iii)
ITEM AMOUNT
Gel Pen Premium 3000
34.
(i) ALTER TABLE Rent_cab ADD CONSTRAINT PRIMARY KEY (Vcode);
(ii) UPDATE Rent_cab SET Charges=Charges+Charges*10/100
(iii) DELETE FROM Rent_cab WHERE Make="Carus";
35.
(i) SELECT Type, AVG(Number) FROM GAMES GROUP BY Type;
(ii) SELECT PrizeMoney, GameName, Name FROM GAMES, PLAYERS
WHERE GAMES.GCode=PLAYERS.GCode;
(iii) SELECT DISTINCT TYPE FROM GAMES;
(iv) SELECT GameName, PrizeMoney FROM GAMES
WHERE PrizeMoney IS NOT NULL;
36.
(A)
(i) select Product, sum(Quantity) from orders group by product having
sum(Quantity)>=5;
(ii) select * from orders order by Price desc;
(iii) select distinct C_Name from orders;
(iv) select sum(price) as total_price from orders where Quantity IS NULL;
(B)
(i)
C_Name Total_Quantity
Jitendra 1
Mustafa 2
Dhwani 1
(ii)
O_Id C_Name Product Quantity Price
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
(iii)
O_Id C_Name Product Quantity Price
1001 Jitendra Laptop 1 12000
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
(iv)
MAX(Price)
12000
37.
(i) Select * from FACULTY natural join COURSES where Salary<12000;
OR
Select * from FACULTY, COURSES where Salary<12000 and
facuty.f_id=courses.f_id;
(ii) Select * from courses where fees between 20000 and 50000;
(iii) Update courses set fees=fees+500 where CName like '%Computer%';
(iv) Select FName, LName from faculty natural join courses where
CName="System Design";
(v) Select * from FACULTY, COURSES;
(b)
Statement 1: mysql.connector
13. (i) A PAN connects devices within the short range of a person, whereas a LAN connects devices at a single
site, typically an office building.
(ii) PAN often uses Bluetooth and USB ports, whereas LAN commonly uses Ethernet or Wi-Fi.
14. FTP
15. (i) The physical address of a device is its permanent address, whereas its IP address is temporary.
(ii) Physical address is allocated at the time of device manufacturing/assembling, whereas logical address is
allocated when the device is connected to a network.
16. (i) Guided media is wired media, whereas unguided media is wireless media. Examples: Coaxial Cable,
Twisted Pair Cable, Fiber Optics Cable.
(ii) Guided media offers better data security than unguided media. Examples: Infrared Rays, Radio waves,
Micro waves
17. (i) Remote login is a process in which user can login into remote site i.e. computer and use services that are
available on the remote computer.
(ii) A Remote desktop is a program or an operating system feature that allows a user to connect to a computer
in another location, see that computer's desktop and interact with it as if it were local.
18. (i) HTML is mainly used to create the layout and structure of web pages, whereas XML is used for defining
custom data structures and allowing data to be shared across different systems.
(ii) HTML has predefined tags that are used to describe the content, whereas there are no predefined tags in
XML. In XML we can design our own to suit the needs.
19. (i) In bus topology, all devices (computers, printers, etc.) are connected to a single central cable (the bus). This
central cable acts as a shared communication medium.
In star topology, each device is connected to a central hub or switch. The hub manages data traffic between
devices.
(ii) Bus topology is not very scalable; adding new devices can cause signal degradation and network
congestion.
Star topology is easier to scale compared to bus topology. New devices can be added without significant impact
on performance.
20. (i) In Star topology all devices are connected to a central hub or switch, whereas Tree topology is a combination
of star topologies connected in a hierarchical manner.
(ii) In Star topology data passes through the central hub before reaching its destination, whereas in Tree
topology data may have to pass through multiple hubs and switches as it travels up and down the hierarchy.
21. (i) Bus topology
22.
23.
Advantages:
1. Simplicity: Bus topology is easy to set up and requires less cable compared to other topologies, making it
cost-effective.
2. Scalability: Adding new devices to the network is straightforward without disrupting the existing
network.
Disadvantages:
1. Limited Length: The length of the bus cable is limited, which can restrict the size of the network.
2. Troubleshooting: If there is a problem with the main cable (bus), the entire network can go down,
making it difficult to troubleshoot.
24.
Advantages:
1. Easy to Manage: Since all devices are connected to a central hub, it's simple to manage and troubleshoot.
If one device fails, it doesn't affect the rest of the network.
2. Scalability: Adding new devices is straightforward. You just connect them to the central hub without
disrupting the existing network.
Disadvantages:
1. Single Point of Failure: If the central hub fails, the entire network goes down, which can be a significant
drawback.
2. Cost: It can be more expensive to set up compared to other topologies because it requires more cable and
a central hub.
25.
Advantages:
1. Cost-Effective: Twisted pair cables are generally cheaper compared to other guided media like coaxial
cables and fiber optics, making them a budget-friendly option for many networks.
2. Flexibility: They are easy to install and can be used in a variety of network setups, from small home
networks to larger business networks.
Disadvantages:
1. Limited Bandwidth: Twisted pair cables have lower bandwidth compared to coaxial cables and fiber
optics, which can limit the speed and capacity of the network.
2. Susceptibility to Interference: They are more prone to electromagnetic interference and crosstalk, which
can affect the quality of the signal.
26.
Advantages:
1. Higher Bandwidth: Coaxial cables offer higher bandwidth compared to twisted pair cables,
allowing for faster data transmission.
2. Less Interference: They are less susceptible to electromagnetic interference, providing a more
stable and reliable connection.
Disadvantages:
1. Cost: Coaxial cables are generally more expensive than twisted pair cables, which can increase
the overall cost of the network setup.
2. Flexibility: They are less flexible and harder to install, especially in tight or complex spaces,
compared to twisted pair cables.
27.
Advantages:
1. High Bandwidth: Optical fiber cables offer significantly higher bandwidth compared to other
guided media, allowing for faster data transmission over long distances.
2. Immunity to Interference: They are immune to electromagnetic interference, providing a more
stable and reliable connection, especially in environments with high electrical noise.
Disadvantages:
1. Cost: Optical fiber cables are generally more expensive to install and maintain compared to
twisted pair and coaxial cables, which can increase the overall cost of the network setup.
2. Fragility: They are more fragile and can be easily damaged if not handled properly, requiring
careful installation and maintenance.
28.
Advantages:
1. Security: Infrared rays are confined to a specific area and do not penetrate walls, making them
more secure compared to other unguided media.
2. Interference-Free: They are less prone to electromagnetic interference, providing a stable and
reliable connection in environments with high electrical noise.
Disadvantages:
1. Line of Sight: Infrared communication requires a clear line of sight between the transmitter and
receiver, which can be obstructed by physical objects.
2. Limited Range: The range of infrared communication is relatively short, making it less suitable for
long-distance communication compared to other unguided media.
29.
Advantages:
1. Long Range: Radio waves can travel long distances, making them suitable for wide-area
communication, such as broadcasting and mobile networks.
2. Penetration: They can penetrate through walls and obstacles, providing better coverage in
buildings and urban areas.
Disadvantages:
1. Interference: Radio waves are susceptible to electromagnetic interference from other electronic
devices, which can affect the quality of the signal.
2. Security: Since radio waves can travel long distances and penetrate walls, they are more
vulnerable to unauthorized access compared to other unguided media.
30.
Advantages:
1. High Bandwidth: Microwaves offer higher bandwidth compared to other unguided media, allowing
for faster data transmission.
2. Long Distance Communication: They can cover long distances and are often used for satellite
and long-distance telephone communications.
Disadvantages:
1. Line of Sight: Microwaves require a clear line of sight between the transmitter and receiver, which
can be obstructed by physical objects.
2. Weather Sensitivity: They are susceptible to weather conditions like rain and fog, which can
affect the quality of the signal.
c) Switch
d) WAN, as the geographical area beyond the limits of MAN.
c) (i) Switch should be placed in each building to interconnect the computers in that
building.
(ii) Repeater should be placed between JAMUNA and RAVI as the distance between
these buildings is more than 90 meters.
d) Optical Fiber
b)
c) LAN
d) Satellite
b)
c) Satellite Link
d) Switch
c) Firewall
d) Video Conferencing
c) Switch
d) VoIP
OR
Optical Fibre cable. It offers extremely efficient data transfer.
(Both the options are correct with valid reason)
(iii) LAN, as the total area covered has the radius of just a few meters.
(iv) No. Distance between any two buildings is much less than 90 meters.
(v) Firewall
(iv) Switch/Hub – In each block to interconnect the computers within that block.
Router – Development block to interconnect the networks of the three blocks.
(v) Using Satellite connection.
10. (i)
(ii) Switch
(iii) Admin Centre because Admin Centre has the maximum number of computers.
(iv) WAN will be formed because the geographical distance between the campuses is more
than the limit of MAN.
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
7. If gold is a dictionary as defined below, then which of the following statements will create (1)
a dictionary with maximum length?
gold = {'Number': 79, 'mass': 196.97, 'valency': 1}
(A) gold.fromkeys('gold',gold)
(B) gold.fromkeys(gold)
(C) gold.fromkeys(gold,'gold')
(D) gold.fromkeys(gold,gold)
10. What will be the output of the following code segment? (1)
a = 20
def add():
global a
a+=5
print(a,end='#')
add()
a=15
print(a,end='%')
(A) 25%15#
(B) 15#25%
(C) 25#15%
(D) 25%15#
11. Write the missing statement to complete the following code: (1)
file = open("myfile.csv", "r")
data = file.read(100)
____________________ #Set the value of file pointer to 20
next_data = file.read(50)
file.close()
12. What happens to the degree/cardinality of a table when we add 5 records to it? (1)
13. Which SQL command is used to delete a column from a table? (1)
17. Which protocol is used to establish a direct connection between two networking devices? (1)
(A) HTTP
(B) FTP
(C) PPP
(D) HTTPS
18. Which network device is used to receive an incoming signal, amplify/regenerate it, and (1)
send it forward?
(A) Modem
(B) Gateway
(C) Switch
(D) Repeater
19. In which network topology all the computers are connected to a central networking device? (1)
Questions 20 and 21 are Assertion (A) and Reasoning (R) based questions. Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): We can define multiple functions with the same name in a Python script. (1)
Reasoning (R): Multiple functions with the same name are called simultaneously.
22. What is the use of in operator in Python? Give an example to explain. (2)
23. Identify two Arithmetic operators and two Logical operators in the following expression: (2)
5+2>3 and 3-5<5 or 5/2!=5*2 or not 5==10
(II)
A) Write a statement to create a copy (not an alias) of L1 and name it as L3.
OR
B) Write a statement to delete the last element of L2.
25. Identify the correct possible output(s) of the following code. Also write the minimum and (2)
the maximum possible values of the variable Pass.
26. The function provided below is intended to find and return the sum of all the factors of (2)
a given number (n). For example, if the value of n is 6, the function should return 12
(1+2+3+4+6). However, there are syntax and logical errors in the code. Rewrite it after
removing all errors. Underline all the corrections made.
def sumFact(n)
s=0
for i in range(n):
if n%i=0:
s+=i
return s
28. A) List one advantage and one disadvantage of radio waves as medium of communication. (2)
OR
B) Expand the term XML. What is the use of XML?
Section-C ( 3 x 3 = 9 Marks)
29. A) Write a Python function that displays all the words starting with a lowercase vowel (3)
from a text file "DomHelp.txt". In the output consecutive words should be separated
by a space. For example, if the file contains
The lives of domestic helpers are full of hardships.
They do a lot of work in the employer's house.
Then the output should be:
of are of a of in employer's
OR
B) Write a Python function that counts and displays the number of lowercase vowels in a
text file "DomHelp.txt". For example, if the file contains
The lives of domestic helpers are full of hardships.
They do a lot of work in the employer's house.
Then the output should be:
29 lowercase vowels in the file
30. (A) You have a stack named HelpStack that contains records of Domestic Helpers. Each (3)
record in the stack is represented as a list containing H_Code, H_Name, H_Mobile,
H_Address.
SECTION D (4 X 4 = 16 Marks)
32. Based on the table Dhelp, as given below, answer part A to write the queries OR part B (4)
to write the output of the given queries.
Table: DHelp
+------+--------+--------+------+------------+
| Code | Name | Gender | Age | Mobile |
+------+--------+--------+------+------------+
| 1 | Anubha | F | 34 | 1122334455 |
| 2 | Basil | M | 28 | 2233445511 |
| 8 | Chris | M | 32 | 1100334455 |
| 4 | Sania | F | 27 | 1100334465 |
| 6 | Ashish | M | 32 | 1100334565 |
| 5 | Xavier | M | 28 | 1201334565 |
| 7 | Arifa | F | NULL | NULL |
+------+--------+--------+------+------------+
A)
I. To display all the records in the ascending order of Code.
II. To display the mobile numbers of all the records where Gender is M and Age is
less than 30.
III. To display the maximum age and minimum age from the table.
IV. To display all those names for which the Mobile is not available.
OR
B)
I. select gender, avg(age) from dhelp group by gender;
II. select Code, Name from dhelp where mobile like '%0%';
III. select Code, Name, Age from dhelp where age between 28 and
32;
IV. select count(age) from dhelp;
33. A csv file "DomHelp.csv" contains the data of Domestic Helpers in India. Each record of (4)
the file contains the following data:
• ID (integer)
• Helper’s Name
• Helper’s Gender
• Weekly Work Hours
• Weekly Salary
For example, a sample record of the file may be:
3129, 'Bhanumati', 'F', 20, 2000
Write the following Python functions to perform the specified operations on this file:
(I) Read all the data from the file and display all those records for which the
hourly salary is less than 100 .
(hourly salary = weekly salary / weekly work hours)
(II) Count and display the number of records in the file.
34. Kynara runs a Domestic Help service. She has a database which contains two tables Dhelp (4)
and Contract. Dhelp stores the personal details of helpers, and Contract stores the
employment details of helpers. Sample data from both these tables is given below:
Table: DHelp
+------+--------+--------+------+------------+
| Code | Name | Gender | Age | Mobile |
+------+--------+--------+------+------------+
| 1 | Anubha | F | 34 | 1122334455 |
| 2 | Basil | M | 28 | 2233445511 |
| 8 | Chris | M | 32 | 1100334455 |
| 4 | Sania | F | 27 | 1100334465 |
| 6 | Ashish | M | 32 | 1100334565 |
| 5 | Xavier | M | 28 | 1201334565 |
| 7 | Arifa | F | NULL | NULL |
+------+--------+--------+------+------------+
Table: Contract
+-------+------------+----------+--------+
| HCode | StartDate | Duration | Salary |
+-------+------------+----------+--------+
| 1 | 2024-10-21 | 12 | 12000 |
| 2 | 2024-12-11 | 10 | 11000 |
| 6 | 2024-12-15 | 11 | 13000 |
| 7 | 2025-01-12 | 15 | 11000 |
+-------+------------+----------+--------+
From these two tables we can infer that Anubha got into an employment contract for 12
months on 21st December 2024 at a salary of 12000 per month.
As an assistant to Kynara, help her to extract the following information by writing the
desired SQL queries as mentioned below.
(I) To display the Name and Mobile of all the helpers who are hired for a Salary more
than 11000.
(II) To display the details of contract whose duration is in the range of 10 to 12 (both
values included), along with the name of the corresponding Helper from the
Dhelp table.
(III) To increase the Salary of all the contracts by 10%.
(IV) (A) To display Name and Gender of all helpers who were hired in the month of
December.
OR
(B) To make Code the primary key of the table Dhelp.
35. A table, named DHelp, in DomServices database, has the following structure: (4)
+--------+-------------+
| Field | Type |
+--------+-------------+
| Code | int(5) |
| Name | varchar(20) |
| Gender | char(1) |
| Age | int(2) |
| Mobile | char(10) |
+--------+-------------+
Write the following Python function to perform the specified operation:
UpdateAndDisplay(): To increase the Age of each record by 1. The function
should then retrieve and display all records from the
DHelp table where the Gender is M.
SECTION E (2 X 5 = 10 Marks)
36. Zian is a manager of a Sales agency. He needs to manage the records of various Sales (5)
persons. For this he wants the following information of each Sales person to be stored:
S_ID – integer
S_Name – string
Experience – float
S_Rating - integer
You, as a programmer of the agency, have been assigned to do this job for Zian:
(I) Write a function to input the data of a Sales person and append it in a binary
file 'Sales.dat'.
(II) Write a function to input an S_ID and display the corresponding record from
the file 'Sales.Dat'. If the record is not found, then the function should display
the message "Record Not Found".
(III) Write a function to read the data from the file and display the number of
records where S_Rating is more than 4.
37. XLTech is a software development company with its Head Office in Chennai (in India). It (5)
is planning to set up a new campus in Aurangabad (in India). The Aurangabad campus will
have four blocks/buildings - Admin, Development, Back End, and Research.
Distance between various blocks, and Number of Computers in each block is given below:
From To Distance Block Computers
ADMIN Development 24 m Admin 10
ADMIN Back End 24 m Development 30
ADMIN Research 24 m Back End 50
Development Back End 50 m Research 20
Development Research 50 m
Back End Research 60 m
You, as a network expert, need to suggest the best network-related solutions for them to
resolve the issues/problems mentioned in points (I) to (V), keeping in mind the distances
between various blocks/buildings and other given parameters.
(I) Suggest the most appropriate location of the server inside the Aurangabad
campus. Justify your choice.
(II) Which hardware device will you suggest to connect all the computers within
each building?
(III) Draw the cable layout to efficiently connect various buildings within the
Aurangabad campus. Which cable would you suggest for the most efficient data
transfer over the network?
(IV) Is there a requirement of a repeater in the given cable layout? Why/ Why not?
(V) (A) What would be your recommendation to wirelessly connect Aurangabad
campus to Chennai Head Office in an economical way? Select an option from
the following:
a) Satellite Link
b) Microwave connection
c) Radio wave connection
OR
(B) What type of network (PAN, LAN, MAN, or WAN) will be set up among the
computers connected within the Aurangabad campus?
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
7. If book is a dictionary as defined below, then which of the following statements will (1)
change the length of the dictionary?
book = {'Code': '004', 'Edition': 2024, 'Price': 100}
(A) book.get(1)
(B) book.setdefault(1)
(C) book.update({'Code':'005'})
(D) book['Edition']=2025
8. What type of parameter, out of the following, is valid for the list.extend() method? (1)
(A) int
(B) float
(C) str
(D) None of these
11. Write the missing statement to complete the following code: (1)
file = open("myfile.csv", "r")
data = __________ #read first 50 characters from the file
file.close()
12. What happens to the degree/cardinality of an existing table when we remove Primary key (1)
constraint from it?
13. Which SQL command is used to add a column to an existing table? (1)
15. Which of the following is a valid entry in the date type column of a table in MySQL? (1)
(A) '12-21-2024'
(B) '21-12-2024'
(C) '2024-12-21'
(D) '2024-21-12'
17. Which protocol is used to transfer files over a TCP/IP network? (1)
(A) HTTP
(B) FTP
(C) PPP
(D) HTTPS
18. Which network device is used to connect two segments of a LAN? (1)
(A) Modem
(B) Gateway
(C) Switch
(D) Router
19. In which network topology all the computers are connected to a common cable? (1)
Questions 20 and 21 are Assertion(A) and Reasoning(R) based questions. Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): We cannot define multiple functions with the same name in a Python script. (1)
Reasoning (R): A function is executed only when it is called.
22. Give an example of a Boolean expression in Python. What are the possible values of a (2)
Boolean expression?
24. If S1="Web", and S2="Programming", then do the following using built-in (2)
functions/methods only:
(I)
A) Write a statement to display S2 in upper case.
OR
B) Write a statement to create a list containing characters of S1 as its elements.
(II)
A) Write a statement to display the number of times 'm' appears in S1.
OR
B) Write a statement to display W-e-b by applying a string method on S1.
25. Identify the correct possible output(s) of the following code. Also write the minimum and (2)
the maximum possible values of the variable Pos.
from random import randrange
for i in range(4):
Pos=randrange(i+4)
print(Pos,end='-')
26. The function provided below is intended to find and return the sum of the digits of a (2)
given positive integer (n). For example, if the value of n is 621, the function should return
9 (6+2+1). However, there are syntax and logical errors in the code. Rewrite it after
removing all errors. Underline all the corrections made.
def sumDigits(n):
s==0
while n=0:
d=n//10
s+=d
n//=10
Return s
28. A) List one advantage and one disadvantage of Micro waves as medium of communication. (2)
OR
B) Expand the term HTML. What is the use of HTML?
Section-C ( 3 x 3 = 9 Marks)
29. A) Write a Python function that displays all the lines ending with a lowercase vowel from (3)
a text file "Juice.txt". For example, if the file contains
Juices like beetroot juice, pomegranate
and citrus are heart-healthy due to their
antioxidant content and ability to
improve circulation, reduce blood pressure,
and lower cholesterol levels.
Then the output should be:
Juices like beetroot juice, pomegranate
antioxidant content and ability to
OR
B) Write a Python function that counts and displays the number of 5 letter words in a text
file "Juices.txt". In the output consecutive words should be separated by a space.
For example, if the file contains
Juices like beetroot juice, pomegranate
and citrus are heart-healthy due to their
antioxidant content and ability to
improve circulation, reduce blood pressure,
and lower cholesterol levels.
Then the output should be:
their blood lower
30. (A) A stack named Juices contains records of some juices. Each record in the stack is (3)
represented as a list containing Name, Size, Price.
Write the following user-defined functions in Python to perform the specified
operations on the stack Juices:
SECTION D (4 X 4 = 16 Marks)
32. Based on the table Drinks, as given below, answer part A to write the queries OR part B (4)
to write the output of the given queries.
Table: Drinks
+-------+------+-------+------------+
| Name | Size | Price | Remarks |
+-------+------+-------+------------+
| Apple | S | 0.75 | Apple Only |
| Apple | M | 1 | Apple Only |
| Apple | L | 1.5 | Apple Only |
| Mango | L | 2 | Shake |
| Mango | M | 1.5 | Shake |
| Mango | S | 0.75 | Mango Only |
+-------+------+-------+------------+
A)
I. To display the average price of each kind of drink based on its Name.
II. To display the details of all drinks where Remarks is Shake.
III. To display the number of records where Remarks contains 'Only'.
IV. To display all those records where price is less than 1.
OR
B)
I. select name, price from drinks where size in ('S','M');
II. select min(price), max(price) from drinks group by size;
III. select distinct(size) from drinks;
IV. select Name, Size, Price from Drinks
where price between 1 and 2 order by price;
33. A csv file "Juices.csv" contains the records of Juices made by a Juice manufacturer. Each (4)
record of the file contains the following data:
• ID (5 character string)
• Content (Main Fruit's Name – a string)
• Sugar (A single character string - Y for Yes and N for No)
• Qty (integer)
• Price (integer)
For example, a sample record of the file may be:
'MSF12', 'Mango', 'N', 150, 20
Write the following Python functions to perform the specified operations on this file:
(I) Append a record to the file. Data should be input from the user.
(II) Display all those records from the file for which Sugar is 'N'.
34. Abhishek manages a Fruit Juice Sales agency. He has a database which contains two tables (4)
- Juices and Orders. Juices stores the details of juices and Orders stores the details of
the orders received. Sample data from both these tables is given below:
Table: Juices
+-------+---------+-------+------+-------+
| J_ID | Content | Sugar | Qty | Price |
+-------+---------+-------+------+-------+
| MSF12 | Mango | N | 150 | 20 |
| ASF12 | Apple | N | 150 | 20 |
| MXS25 | Mix | Y | 250 | 50 |
| GrS35 | Grapes | Y | 1000 | 250 |
+-------+---------+-------+------+-------+
Table: Orders
+------+------------+-------+-------+----------+
| O_No | O_Date | J_ID | O_Qty | Discount |
+------+------------+-------+-------+----------+
| 201 | 2024-12-15 | ASF12 | 50 | 0.5 |
| 108 | 2024-12-21 | MXS25 | 100 | 0.75 |
| 12 | 2025-01-03 | MSF12 | 100 | NULL |
+------+------------+-------+-------+----------+
As a database expert, help Abhishek to extract the following information by writing the
desired SQL queries as mentioned below.
(I) To display the details of all the juices for which some order has been placed.
(II) To display the details of all the orders placed in the year 2024 along with the
corresponding Content from the table Juices.
(III) To display the value of each order after considering the discount.
(value = O_Qty*Price*(100-Discount))
(IV) (A) For some records the value of discount is NULL, and for some other records it
is 0. Display the corresponding J_ID and Price for all such orders.
OR
(B) To add a column BalQty of type int(4) to the table Juices.
35. A table, named Juices, in AbhiSales database, has the following structure: (4)
+---------+-------------+
| Field | Type |
+---------+-------------+
| J_ID | char(5) |
| Content | varchar(10) |
| Sugar | char(1) |
| Qty | int(4) |
| Price | int(4) |
+---------+-------------+
Write the following Python function to perform the specified operation:
DeleteAndDisplay(): To input a J_ID from the user and delete the corresponding
record from the table. The function should then retrieve
and display all records from the Juices table.
SECTION E (2 X 5 = 10 Marks)
36. Rajesh is a production manager working in an Export firm. He needs to manage the records (5)
of employees working for him. For this he wants the following information of each
employee to be stored:
E_ID – integer
E_Name – string
E_Age – integer
E_Salary - integer
Experience – float
You, as a programmer of the company, have been assigned to do this job for Rajesh:
(I) Write a function to input the data of an employee and append it in a binary
file 'Emp.dat'.
(II) Write a function to input an E_ID and display the corresponding record from
the file 'Emp.Dat'. If the record is not found, then the function should display
the message "Record Not Found".
(III) Write a function to read the data from the file and display the number of
records where E_Age is less than 30.
37. Total Health is a chain of Hospitals with its Head Office in Panipat. It has a big hospital in (5)
Rourkela which is 1500km away from Panipat. Rourkela hospital has four major blocks –
Admin, Inpatient, Outpatient, and Emergency.
Distance between various blocks, and Number of Computers in each block is given below:
From To Distance Block Computers
ADMIN Inpatient 24 m Admin 10
ADMIN Outpatient 24 m Inpatient 30
ADMIN Emergency 24 m Outpatient 50
Inpatient Outpatient 50 m Emergency 20
Inpatient Emergency 50 m
Outpatient Emergency 60 m
The management of Total Health wants to restructure the existing Computer Network
setup in Rourkela hospital. You, as a network expert, need to suggest the best network-
related solutions for them to resolve the issues/problems mentioned in points (I) to (V),
keeping in mind the distances between various blocks/buildings and other given
parameters.
(I) Suggest the most appropriate location of the server inside the Aurangabad
campus to ensure maximum safety of the server. Justify your choice.
(II) Which hardware device will you suggest to connect all the computers within
each block?
(III) Draw the cable layout to efficiently connect various blocks of Rourkela
hospital. Which device will you suggest to interconnect the networks of various
blocks?
(IV) Is there a requirement of a repeater in the given cable layout? Why/ Why not?
(V) (A) What would be your recommendation to wirelessly connect Rourkela
hospital to Panipat Head Office. Keep in mind that time is a critical factor in
healthcare services. The connection should be the fastest one. Select an option
from the following:
a) Satellite Link
b) Microwave connection
c) Radio wave connection
OR
(B) The doctors of the Rourkela hospital have to regularly attend online
workshops to keep themselves updated. Which protocol is used for these
workshops which involve audio-visual data communication?
Answer Key
Sample Question Paper-2 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. False (1)
5. (C) 1 3 (1)
6. [2, 4, 6, 8] (1)
9. False (1)
14. (A) Number of non null values in the House column. (1)
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
5. If T1=(1,2,3) then which of the following statements will give syntax error or run time (1)
error?
(A) T1=[1,2,3]
(B) del T1
(C) print(T1[2])
(D) T1[1]=2
7. If rec is a dictionary in Python, then write a statement which creates another dictionary (1)
with the keys of rec and value of each key should be 10.
8. What type of parameter, out of the following, is valid for the list.append() method? (1)
(A) int
(B) tuple
(C) dictionary
(D) All of these
10. What will be the output of the following code snippet? (1)
a=1,2,3,
def f1(a):
a=2,3,4,5
print(len(a),end='—')
f1(a)
print(len(a),end='+')
(A) 4-4+
(B) 3-3+
(C) 3-4+
(D) 4-3+
11. Write the missing statement to complete the following code: (1)
file = open("myfile.csv", "r")
data = __________ #read first line from the file
file.close()
13. Which SQL command is used to view the structure of an existing table? (1)
14. A table contains data of 30 students of a class. The table has 6 columns. The roll numbers (1)
of the students are integers from 101 to 130. What is the domain of the column RollNumber
of this table?
(A) 6
(B) 101, 130
(C) Set of integers from 1 to 30.
(D) Set of integers from 101 to 130.
15. The cardinality of the cartesian product of two tables is equal to the: (1)
(A) sum of the degrees of the tables.
(B) product of the degrees of the table.
(C) sum of the cardinalities of the tables.
(D) product of the cardinalities of the tables.
17. In which of the following switching techniques the data is divided into packets and each (1)
packet follows its own path?
(A) Circuit Switching
(B) Packet Switching
(C) Network Switching
(D) Message Switching
18. Which of the following wireless media is used for short distance communication (For (1)
example, within a room) and cannot cross hard obstacles?
(A) Infrared Rays
(B) Radio Waves
(C) Micro Waves
(D) All of these
19. Which network topology is usually a combination of Tree and Start topologies? (1)
Questions 20 and 21 are Assertion (A) and Reasoning (R) based questions. Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): If n in nums is a valid statement in Python, then nums must be an (1)
iterable.
Reasoning (R): The second operand of in operator must be an iterable.
21. Assertion (A): The number of Alternate Keys of a table can be more than the number of (1)
its Candidate Keys.
Reasoning (R): Each Alternate Key is a Candidate Key.
22. What is a literal in Python? Give an example of an integer literal and a string literal. (2)
24. If S1=" Alpha ", and S2="\n\nBeta ", then do the following using built- (2)
in functions/methods only:
(I)
A) Display S1 without the leading spaces.
OR
B) Remove the trailing spaces from S2 and store the resultant string in the variable
S3.
(II)
A) Display sorted list of characters of S1.
OR
B) Display the length of S2.
25. Identify the correct possible output(s) of the following code. Also write the minimum and (2)
the maximum possible values of the variable b.
import random
for i in range(4,8):
a=random.randint(1,i)
b=random.randrange(i)
print(a+b,end='-')
(A) 1-2-3-4- (B) 5-6-5-7-
(C) 1-10-3-9- (D) 5-9-6-1-
www.yogeshsir.com SQP3-3/8 www.youtube.com/LearnWithYK
SQP-3/XII/CS-083/2025/YK
26. The function provided below is intended to find and display the number of even elements (2)
in a given list (nums) of integers. For example, if the list nums is
[1,2,50,20,23,45,6] then the function should display 4 because the list contains
four even numbers. However, there are syntax and logical errors in the code. Rewrite it
after removing all the errors. Underline all the corrections made.
def countEven(nums)
c=0
for ele in nums:
if ele%2=0:
c=+1
print('c')
28. A) List one advantage and one disadvantage of Bus topology. (2)
OR
B) Expand the term SMTP. What is the use of SMTP?
Section-C ( 3 x 3 = 9 Marks)
29. A) Write a Python function that displays the last word of each line of a text file (3)
"Sports.txt". For example, if the file contains
Sports offer a wide range of benefits,
both physical and mental.
In essence, sports contribute to a
well-rounded and balanced lifestyle
by improving health.
Then the output should be:
benefits
mental
a
lifestyle
health
Note that the trailing comma(,) and dot(.) are not the part of a word.
OR
B) Write a Python function that counts and displays the number of special characters
appearing in a text file "Sports.txt".
Note: Special characters are the characters other than alphabets and digits.
30. (A) Assume that a list contains record of a movie in the following format: (3)
[Movie_ID, Movie_name, Director, Rating]
Write the following user defined functions to perform given operations on the stack
named "Ratings":
(i) Push_Movie(M) - To Push an object containing Movie_name and Director if
its rating is in the range 8 to 9. M is a list containing data of one movie.
(ii) Pop_Movie(M) - To Pop all the objects from the stack and display them.
Also, display the total number of records popped from the stack.
OR
(B) (i) Write a function in Python, Push(Color, S), where Color is a tuple containing
color names, and S is a stack.
The function should push those color names in stack S, whose length is more than 5.
SECTION D (4 X 4 = 16 Marks)
32. Based on the table Movies, as given below, answer part A to write the queries OR part B (4)
to write the output of the given queries.
Table: Movies
+-------+----------------+------+----------------+------------+-------+
| MID | Title | Year | Director | Actor | music |
+-------+----------------+------+----------------+------------+-------+
| MV001 | Chakravyuh | 2012 | Prakash Jha | Abhay Deol | M002 |
| MV002 | Madras Cafe | 2013 | Shoojit Sircar | J. Abraham | M001 |
| MV003 | Jai Gangajal | 2016 | Prakash Jha | P. Chopra | M002 |
| MV004 | Saand Ki Aankh | 2019 | Prakash Jha | T. Pannu | M003 |
| MV005 | Gulabo Sitabo | 2020 | Shoojit Sircar | A. Khurana | M001 |
| MV006 | Sardar Udham | 2021 | Shoojit Sircar | V. Kaushal | M001 |
+-------+----------------+------+----------------+------------+-------+
A)
I. To display the Titles of the movies whose Actor is Abhay Deol.
II. To display the details of all movies released in the year 2012.
III. To display the number of records where Music is 'M001'.
IV. To display the details of all the movies directed by Prakash Jha.
OR
B)
I. select Year, count(*) from movies group by year;
II. select Music, count(*) from movies group by Music;
III. select mid,title from movies where year between 2013 and
2018;
IV. select mid,title,year from movies where director != 'Prakash
Jha' order by title;
33. A csv file "Movies.csv" contains the records of Indian Movies. Each record of the file (4)
contains the following data:
• M_ID (Movie Code – A 5 character string)
• Title (Movie Title - A string)
• Year (Year of release – An integer)
• Director (Name of the Director – A string)
• Music (Musician Code – A 4 character string)
For example, a sample record of the file may be:
['MV002', 'Madras Cafe', 2013, 'Shoojit Sircar', 'M001']
Write the following Python functions to perform the specified operations on this file:
(I) Append a record to the file. Data should be input from the user.
(II) Display the details of all the movies released in the year 2024. At the end
display the total number of such movies.
34. Alisha is a movie lover and likes to keep records of Indian movies. For this, she has created (4)
a database with two tables - Movies and Musician. Movies stores the details of the movies
and Musician stores the details of the musicians. Sample data from both these tables is
given below:
Table: Movies
+-------+----------------+------+----------------+------------+-------+
| MID | Title | Year | Director | Actor | Mu_ID |
+-------+----------------+------+----------------+------------+-------+
| MV001 | Chakravyuh | 2012 | Prakash Jha | Abhay Deol | M002 |
| MV002 | Madras Cafe | 2013 | Shoojit Sircar | J. Abraham | M001 |
| MV003 | Jai Gangajal | 2016 | Prakash Jha | P. Chopra | M002 |
| MV004 | Saand Ki Aankh | 2019 | Prakash Jha | T. Pannu | M003 |
| MV005 | Gulabo Sitabo | 2020 | Shoojit Sircar | A. Khurana | M001 |
| MV006 | Sardar Udham | 2021 | Shoojit Sircar | V. Kaushal | M001 |
+-------+----------------+------+----------------+------------+-------+
Table: Musician
+-------+-----------------+----------+--------+
| Mu_ID | Name1 | Name2 | Movies |
+-------+-----------------+----------+--------+
| M001 | Shantanu Moitra | NULL | 38 |
| M002 | Salim | Sulaiman | 49 |
| M003 | Vishal Mishra | NULL | 28 |
+-------+-----------------+----------+--------+
As a database expert, help Alisha to extract the following information by writing the
desired SQL queries as mentioned below.
(I) To display MID and the corresponding Musician details for the movies with MID
'MV001','MV002', and 'MV006'.
(II) To display MID, Title, and corresponding Name1 for each movie.
(III) To delete the records of all the movies released before 2015.
(IV) (A) To make MID the primary key of Movies table.
OR
(B) To remove the movies column from the Musician table.
35. A table, named Movies, in Cinema database, has the following structure: (4)
+----------+-------------+
| Field | Type |
+----------+-------------+
| MID | char(5) |
| Title | varchar(20) |
| Year | int(4) |
| Director | varchar(20) |
| Music | char(4) |
+----------+-------------+
Write the following Python function to perform the specified operation:
SECTION E (2 X 5 = 10 Marks)
36. Rashid owns a bags showroom. To keep record of the stock in his showroom, he wants to (5)
store all the relevant data in a file. He wants to store the data for each bag as a dictionary
in the following format:
{B_ID : [Brand, Type, Capacity, Price, Warranty]}
where
B_ID is the bag ID of integer type.
Brand is the brand name of string type.
Type describes the type of bag like Backpack, Laptop, Weekender etc.
Capacity is a float value specifying the capacity of the bag in litres.
Price is an integer specifying the price of the bag.
Warranty is an integer specifying the warranty duration (months) of the bag.
You, as a programmer of the company, have been assigned to do this job for Rajesh by
writing the following functions:
(I) Write a function to input the data of a bag and append it in a binary file
'Bags.dat'.
(II) Write a function to input a B_ID and display the corresponding record from
the file 'Bags.Dat'. If the record is not found, then the function should display
the message "Record Not Found".
(III) Write a function to read the data from the file display the average price of
the bags of type 'Laptop'.
37. RXports is an export house with its Head Office in Mumbai. RXports is setting up a new (5)
manufacturing unit in Kolkata, which is 1900km away from Mumbai. Kolkata unit will have
four blocks – Admin, Design, Production, and Packing.
Distance between various blocks, and Number of Computers in each block is given below:
From To Distance Block Computers
ADMIN Design 14 m Admin 10
ADMIN Production 10 m Design 15
ADMIN Packing 14 m Production 50
Design Production 10 m Packing 10
Design Packing 20 m
Production Packing 10 m
You, as a network expert, need to suggest the best network-related solutions for them to
set up the Computer Network in Kolkata Unit by answering the questions mentioned in
points (I) to (V), keeping in mind the distances between various blocks/buildings and other
given parameters.
(I) Suggest the best cable to be used for the network for maximum speed of data
transfer.
(II) How many switches and how many routers should be procured?
(III) Draw a cable layout showing the interconnection of different blocks keeping in
mind that the server is placed in Admin block.
(IV) Which device should be used to ensure data security by preventing
unauthorized transfer of data?
(V) (A) Mention any one drawback of providing Internet access using Wi-Fi instead
of cabled connection?
OR
(B) Name the topology formed within each block.
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
11. Write the missing statement to complete the following code: (1)
file = open("sqp4.txt",'a')
_____________ #write the string "Easy" in the file.
file.close()
14. A table contains data of 30 students of a class. The table has 6 columns. The roll numbers (1)
of the students are integers from 101 to 130. What is the cardinality of this table?
(A) 6
(B) 30
(C) 101
(D) Set of integers from 101 to 130.
18. The Ethernet cable connects the computer to the network through ___________. (1)
(A) Repeater
(B) Gateway
(C) NIC
(D) HTTP
Questions 20 and 21 are Assertion (A) and Reasoning (R) based questions. Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is False but R is True
21. Assertion (A): Adding a row to a table increases the cardinality of the table. (1)
Reasoning (R): Cardinality of a table is the number of rows in the table.
22. What is the difference between title() and capitalize() methods of string object? (2)
What will be the output of the following statement?
print("a bc dE-".title(), "a bc dE".capitalize())
25. Identify the correct possible output(s) of the following code. Also write the minimum and (2)
the maximum possible values of the variable x.
import random
for i in range(2,6):
a=random.randint(1,i)
x="printer"[a]
print(x,end='-')
(A) i-n-r-t- (B) n-r-i-r-
(C) r-t-i-n- (D) r-r-i-r-
26. The function provided below is intended to find and display the number of lowercase (2)
vowels in a given string (s). For example, if the s='An Aeroplane' then the function
should display 4 because the string contains four lowercase vowels. However, there are
syntax and logical errors in the code. Rewrite it after removing all the errors. Underline
all the corrections made.
def countVowels(s)
c=0
for ch in range(s):
if 'aeiou' in ch:
c+=1
print('c')
28. A) What is meant by bandwidth of a channel? What is the unit to measure bandwidth? (2)
OR
B) What is IP address? Give an example of version 4 IP address.
Section-C ( 3 x 3 = 9 Marks)
Write the following user defined functions to perform given operations on the stack
named 'XIIB':
(i) pushStd() - To Push an object containing name and admission number of
students who belong to class 12 and section "B" to the stack
(ii) popStd() - To Pop the objects from the stack and display them. Also, display
"Stack Empty" when there are no more elements in the stack.
For example: If the lists of students details are:
["Rachit", "1122334455",11,"C"]
["Swarit", "2233445511",12, "B"]
["Aanchal","3344551122",10,"A"]
["Yogita", "4455112233",12,"B"]
Then the stack "XIIB" should contain"
["Swarit", "2233445511"]
["Yogita", "4455112233"]
And the output should be:
["Yogita", "4455112233"]
["Swarit", "2233445511"]
Stack Empty
OR
(B) Write a function Push(Classes) in Python, where Classes is a dictionary
containing the number of students in different classes (Class:Strength) of a school
as key:value pairs.
The function should push those Classes in the stack which have strength more than
25. Also display the count of elements pushed into the stack.
For example, if the dictionary contains the following data:
Classes={"12A":28, "12B":30, "12C":23, "11A":22, "11B":27,
"11C":25}
Then the stack should contain "12A", "12B", "11B"
And the output should be: The count of elements in the stack is 3
SECTION D (4 X 4 = 16 Marks)
32. Based on the table Teachers, as given below, answer part A to write the queries OR part (4)
B to write the output of the given queries.
Table: Teachers
+-------+------------+-------+---------+------+------------+------+
| TCode | Name | Desig | SubCode | Age | DOJ | Exp |
+-------+------------+-------+---------+------+------------+------+
| PR101 | Rashmi | PRT | 041 | 28 | 2020-10-10 | 5 |
| PR102 | Bharat | PRT | 041 | 30 | 2020-12-10 | 7 |
| PG008 | Charu | PGT | 043 | 38 | 2022-12-10 | 13 |
| PG010 | Damanpreet | PGT | 042 | 33 | 2022-12-11 | 8 |
| TG010 | Rajesh | TGT | 083 | 44 | 2021-12-12 | 19 |
| TG012 | Asim | TGT | 803 | 40 | 2021-12-12 | 15 |
| PR012 | David | PRT | 042 | 38 | 2019-12-01 | 15 |
+-------+------------+-------+---------+------+------------+------+
A)
I. To increase the age and experience of all teachers by 1.
II. To display the details of all teachers whose subject is '042' and they joined in
the year 2022.
III. To display the minimum age and maximum age of teachers Desig wise.
IV. To display the Name, Age, and SubCode of all the PGTs whose experience is
more than 10.
OR
B)
I. select Name, Exp+2 Exp from teachers order by exp;
II. select count(*) from teachers where desig in ('PGT','TGT');
III. select subcode, count(*) from teachers group by subcode;
IV. select min(doj), max(doj) from teachers;
33. A csv file "Classes.csv" contains the records of different classes in a school. Each record (4)
of the file contains the following data:
• Class (An integer from 1 to 12)
• Section (A single character string)
• Strength (Number of students in the class)
• CT (Name of the Class Teacher)
For example, a sample record of the file may be:
[12, 'B', 30, 'Prasanth K']
Write the following Python functions to perform the specified operations on this file:
(I) Append a record to the file. Data should be input from the user.
(II) Find and display the average number of students in class 12.
34. Ms. Sadhana is a Principal of a school and assume that you are working as a Database (4)
Administrator (DBA) in the school. You have created two tables - Classes and Teachers.
Classes stores the details of the class and Teachers stores the details of the teachers in
the school. Sample data from both these tables is given below:
Table: Classes
+-------+-----+----------+--------+--------+
| Class | Sec | Strength | CTCode | ATCode |
+-------+-----+----------+--------+--------+
| 1 | A | 25 | PR023 | PR005 |
| 1 | B | 23 | PR024 | PR005 |
| 1 | C | 25 | PR012 | PR013 |
| 2 | A | 21 | PR015 | PR013 |
| 2 | B | 23 | PR018 | PR009 |
| 3 | A | 27 | PR019 | PR009 |
+-------+-----+----------+--------+--------+
(Note: Here CTCode is the TCode of the Class Teacher, and ATCode is the TCode of
the Associate Teacher of the class. TCodes are given in the Teachers table.)
Table: Teachers
+-------+----------+------+------------+------+
| TCode | Name | Age | DOJ | Exp |
+-------+----------+------+------------+------+
| PR001 | Prathama | 34 | 2020-07-12 | 10 |
| PR013 | Rashmi | 43 | 2021-07-10 | 18 |
| PR009 | Nazia | 38 | 2020-03-17 | 12 |
+-------+----------+------+------------+------+
Help the Principal to extract the following information by writing the desired SQL queries
as mentioned below.
(I) To display Name, Class, and Section for each Associate Teacher (ATCode)
(II) To display the TCode, Name, and DOJ of each class teacher.
(III) To display the average strength of each class.
(IV) (A) To make Class+Sec the primary key of Classes table.
OR
(B) To add DOB column of type Date in the Teachers table.
35. A table, named Classes, in School database, has the following structure: (4)
+----------+---------+
| Field | Type |
+----------+---------+
| Class | int |
| Sec | char(1) |
| Strength | int |
| CTCode | char(5) |
| ATCode | char(5) |
+----------+---------+
Write the following Python function to perform the specified operation:
AddAndDisplay(): To add a new record with any suitable values in the table. The
function should then retrieve and display all those records
from the table where strength is less than 20.
Assume the following for Python-Database connectivity:
Host: 'localhost', User: 'Guest', Password: 'Sch-JkP'
SECTION E (2 X 5 = 10 Marks)
36. A binary file 'Schools.Dat' stores the information about some schools in a city. Each record (5)
of the file is in the following format:
{Aff_No : [Name, Level, Strength, Principal, WebSite]}
where
Aff_No is the Affiliation Number of the school (integer type)
Name is the name of the school.
Level is the school level ('Primary', 'Middle', 'Sec', or ''Sr. Sec' )
Strength is the number of students studying in the school.
Principal is the name of the Principal.
WebSite is the school's website.
For example, a record in the file might be:
{52814:['YRPS', 'Middle', 2000, 'R Madaan', 'yrps.edu']}
(II) A function to input an Aff_No and delete the corresponding record from the
file. If the record is not found, then the function should display the message
"Record Not Found".
(III) A function to read the data from the file display the records of all the 'Sec'
level schools.
37. A new school 'Proton High School' is being set up. The management of the school plans to (5)
build three computer labs – Primary, Middle, and Senior with 30 computers in each lab.
The Administrative Block will have 15 computers. There will also be 5 computers in the
Activity Block of the school.
Limited access to the Internet (Blocking a number of unwanted websites) will be given in
each lab and in Activity Block. You, as a network consultant, have to help the management
in setting up the Computer Network in the school by answering the following questions,
keeping in mind the distances between various blocks/labs/buildings and other given
parameters.
From To Distance
Administrative Block Primary Lab 50 m
Administrative Block Middle Lab 60 m
Administrative Block Senior Lab 70 m
Administrative Block Activity Block 100 m
Primary Lab Middle Lab 30 m
Primary Lab Senior Lab 30 m
Primary Lab Activity Block 70m
Middle Lab Senior Lab 30m
Middle Lab Activity Block 70m
Senior Lab Activity Block 60m
(I) Suggest the best cable to be used for the network for maximum speed of data
transfer.
(II) Which device will you suggest, that should be placed in each of these Labs,
Administrative Block, and Activity Block, to efficiently connect all the
computers within these blocks/labs?
(III) Draw a cable layout showing the interconnection of different blocks keeping in
mind that the server is placed in Administrative Block.
(IV) Which device should be used to block the access to unwanted websites?
(V) (A) Is the repeater needed in this network setup? Justify your answer.
OR
(B) Name the topology formed within each lab.
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
6. If a= 'Apple and Pineapple' then which of the following statements will display an (1)
empty string?
(A) print(a[2:3:3])
(B) print(a[-3:3:-1])
(C) print(a[3:-3:-1])
(D) print(a[:5:5])
8. If nums=['1','2','3'] then which of the following statements will raise an error? (1)
(A) nums[1]==2
(B) nums[2].isupper()
(C) nums[3]='4'
(D) nums=123
11. Write the missing statement to complete the following code: (1)
file = open("sqp4.txt", __) #open the file in suitable mode
file.read(20)
file.close()
17. Identify the invalid IPv4 Address from the following: (1)
(A) 1.2.3.4
(B) 255.255.255.0
(C) 198.302.192.1
(D) 60.60.60.60
Questions 20 and 21 are Assertion (A) and Reasoning (R) based questions. Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): If f1.read(20) is a valid statement in Python, then f1 cannot be a binary (1)
file object.
Reasoning (R): read() method is not valid for binary files.
21. Assertion (A): We cannot use WHERE clause instead of HAVING clause with GROUP BY (1)
clause.
Reasoning (R): WHERE clause is used to apply conditions on individual rows, whereas
HAVING clause is used to apply conditions on groups.
22. (I) Name two functions of the random module which always generate integers. (2)
(II) Name two functions of the random module which always generate floating point
numbers.
24. If S1="Applied" and S2="Mathematics" then do the following using built-in (2)
functions/methods only:
(I)
A) Display S1 in uppercase.
OR
B) Display S2 in lowercase.
(II)
A) Display the number of times 'a' appears in S2.
OR
B) create a sorted list of the characters of S1. Name the list as LS1.
25. Identify the correct possible output(s) of the following code. Also write the minimum and (2)
the maximum possible values of the variable a.
T=(15,48,32,49,65,36)
for i in range(1,5):
a=random.randrange(i)+2
print(T[a],end='-')
(A) 49-32-49-65- (B) 32-32-49-65-
(C) 32-32-49-49- (D) 32-65-49-65-
26. The function provided below is intended to find and return the sum of all the even factors (2)
of an integer (n). For example, if the n=18 then the function should display 26
(2+6+18) because 2, 6, and 18 are the even factors of 18. However, there are syntax
and logical errors in the code. Rewrite it after removing all the errors. Underline all the
corrections made.
def f1(n):
s=0
for i in range(n+1)
if i%2==0 and n%i:
s+=i
return i
27. If a table 'Teachers' stores the data of 50 teachers of a school. The table has the following (2)
structure:
+---------+-------------+
| Field | Type |
+---------+-------------+
| TCode | char(5) |
| Name | varchar(15) |
| Desig | char(5) |
| SubCode | char(3) |
| Age | int(2) |
| DOJ | date |
| Exp | int(2) |
| Dob | date |
+---------+-------------+
Minimum valid Age is 23 and maximum valid Age is 60.
Desig (Designation) of a teacher can be 'PRT', 'TGT', or 'PGT'
28. A) Give one suitable example of each – URL and Domain Name. (2)
OR
B) Write any two differences between PAN and LAN types of networks.
Section-C ( 3 x 3 = 9 Marks)
29. A) "TV.txt" is a text file. write a Python function that counts and displays (3)
(i) Number of capital alphabets appearing in the file.
(ii) Number of 5 letter words appearing in the file.
(iii) Number of lines with at least 5 words appearing in the file.
OR
B) Write a Python function that reads a text file 'TV.txt', and displays the first and the last
letter appearing in each line of the file. s:
Television (TV) is an effective medium for communication.
Television is a vast medium of entertainment, information,
and education of the modern age. Television was invented
in 1925 by John Logie Baird.
Television enables children to learn moral lessons in a fun
way with special channels and programs meant for children.
a,b=5,7
a,b=f1(a)
b,a=f1(b)
print(a,b)
OR
B) Predict the output of the following code:
def f1(x,y=5):
global a,b
a//=x
if b%3>1:
a+=x+y
else: a-=x-y
print(a,x)
return(a,x)
a,b=15,17
a,b=f1(a)
b,a=f1(b,a)
print(a,b)
SECTION D (4 X 4 = 16 Marks)
32. Based on the table TV, as given below, answer part A to write the queries OR part B to (4)
write the output of the given queries.
Table: TV
+---------+----------+------+---------+------------+-------+
| Brand | Model | Size | Display | Resolution | Price |
+---------+----------+------+---------+------------+-------+
| Sony | Bravia | 55 | LED | 4K | 59000 |
| Sony | Bravia 2 | 43 | LED | 4K | 39000 |
| Acer | GTV | 43 | QLED | 4K | 26000 |
| Acer | Pro | 50 | QLED | NULL | 27000 |
| LG | Pro | 32 | LED | 720p | 14000 |
| Samsung | Crystal | 65 | OLED | UHD | 68000 |
+---------+----------+------+---------+------------+-------+
A)
I. To decrease the price of Sony TVs by 5%.
II. To display the details of all TVs with 4K resolution.
III. To display the Brand and the corresponding number of records for each Brand.
IV. To delete all the records where Resolution is NULL.
OR
B)
I. select Brand, Size from TV where price<30000;
II. select Brand, Size, Price from TV
where resolution != '4K' order by price desc;
III. select avg(price) from TV where display='LED';
IV. select Model, Size, Display from TV
where Brand in ('Sony','Samsung');
33. A csv file "TV.csv" contains the records of different TVs in an electronics shop. Each record (4)
of the file contains the following data:
• Brand (string type)
• Model (string type)
• Size (integer type)
• Price (float type)
For example, a sample record of the file may be:
['SONY', 'Bravia', 55, 59000]
Write the following Python functions to perform the specified operations on this file:
(I) Append a record to the file. Data should be input from the user.
(II) Display all the records where Price<30000.
34. Sonia is a marketing manager in an electronics showroom. She has created two tables - (4)
TV and Bills. TV stores the details of the TVs in the showroom and Bills stores the details
of the bills of TVs sold. Sample data from both these tables is given below:
Table: TV
+------+---------+----------+------+---------+------------+-------+
| T_ID | Brand | Model | Size | Display | Resolution | Price |
+------+---------+----------+------+---------+------------+-------+
| 1 | Sony | Bravia | 55 | LED | 4K | 59000 |
| 2 | Sony | Bravia 2 | 43 | LED | 4K | 39000 |
| 3 | Acer | GTV | 43 | QLED | 4K | 26000 |
| 4 | Acer | Pro | 50 | QLED | NULL | 27000 |
| 5 | LG | Pro | 32 | LED | 720p | 14000 |
| 6 | Samsung | Crystal | 65 | OLED | UHD | 68000 |
+------+---------+----------+------+---------+------------+-------+
Table: Bills
+---------+------------+------+----------+
| BNo | BDate | T_ID | Discount |
+---------+------------+------+----------+
| 2024195 | 2024-12-15 | 2 | 0.05 |
| 2024196 | 2024-12-15 | 6 | 0 |
| 2024213 | 2024-12-26 | 1 | 0.1 |
| 2025006 | 2025-01-07 | 2 | 0.05 |
| 2025019 | 2025-01-11 | 1 | 0.07 |
+---------+------------+------+----------+
As a database expert you have to help Sonia to extract the following information by
writing the desired SQL queries as mentioned below.
(I) To display the details of all the TVs sold in 2024.
(II) To display the Bill details corresponding to TVs of brand 'Sony'.
(III) To display the Bill Number (BNo) and T_ID of all the TVs of size less than 50.
(IV) (A) To make T_ID the primary key of TV table.
OR
(B) To add Cust column of type int in the Bills table.
35. A table, named TV, in SSA database, has the following structure: (4)
+------------+-------------+
| Field | Type |
+------------+-------------+
| T_ID | int(11) |
| Brand | varchar(15) |
| Model | varchar(10) |
| Size | int(3) |
+------------+-------------+
Write the following Python function to perform the specified operation:
AlterAndDisplay(): To add a new column Price of type float in the table.
The function should then retrieve and display all those records
from the table where size is not equal to 50.
Assume the following for Python-Database connectivity:
Host: 'localhost', User: 'Guest', Password: 'Sd@SSA'
SECTION E (2 X 5 = 10 Marks)
36. A binary file 'TV.Dat' stores the information about some TVs in in an electronics shop. (5)
Each record of the file is a list in the following format:
[T_ID, Brand, Model, Size, Price]
where
T_ID is the TV’s identification number (integer type)
Brand is the Brand Name (Like ‘Sony’, ‘Samsung’, ‘LG’ etc.)
Model is the Model Name of the TV (string type)
Size is the Screen Size (integer type)
Price is the price of the TV (integer type)
For example, a record in the file might be:
[1, 'Sony', 'Bravia', 55, 59000]
Write the following functions with reference to this file:
(I) A function to input the data of a TV and append it to the file.
(II) A function to increase the price of Samsung brand TVs by 10%.
(III) A function to read the data from the file display all those records where Price
is more than 50000.
37. Impact Edu Care Ltd. is an educational organization with its Head Office in Delhi. It is (5)
planning to setup a new Campus in Pathankot (in India). The Pathankot campus will have
4 main buildings – ADMIN, ENGINEERING, BUSINESS and MEDIA.
(I) Suggest the most appropriate location of the server inside the PATHANKOT campus
(out of the 4 buildings), to get the best connectivity for maximum no. of
computers. Justify your answer.
(II) Suggest and draw the cable layout to efficiently connect various buildings within
the PATHANKOT campus for connecting the computers.
(III) Which hardware device will you suggest to be procured by the company to be
installed to protect and control the internet access within the campus?
(IV) Which of the following will you suggest to establish the online face-to-face
communication between the people in the Admin Office of PATHANKOT campus
and DELHI Head Office?
(i) Cable TV (ii) Email (iii) Video Conferencing (iv) Text Chat
(V) (A) Is there a requirement of switch(es)? Justify your answer.
OR
(B) Is there a requirement of router(s)? Justify your answer.
Answer Key
Sample Question Paper-1 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. True (1)
5. (C) 6 (1)
6. sisp (1)
9. False (1)
14. (B) Unrepeated values from the House column of table Students. (1)
21. (A) Both A and R are true and R is the correct explanation for A. (1)
22. in operator is used to check whether an object is a member of an iterable. For example, (2)
1 in [1,2,3] will return True because 1 is an element of the list [1,2,3]. 4 in
[1,2,3] will return False because 4 is not an element of the list [1,2,3]
(II)
A) L3=L1.copy()
OR
B) L2.pop().
28. A) (2)
Advantages:
Penetration: They can penetrate through walls and obstacles, providing better
coverage in buildings and urban areas.
Disadvantages:
Interference: Radio waves are susceptible to electromagnetic interference from
other electronic devices, which can affect the quality of the signal.
OR
B) XML – Extensible Markup Language.
XML is used to define and store data in a shareable manner.
Section-C ( 3 x 3 = 9 Marks)
29. A) (3)
def vow_Words():
f=open("DomHelp.txt")
data=f.read()
words=data.split()
for word in words:
if word[0] in 'aeiou':
print(word,end=' ')
f.close()
OR
B)
def countVow():
f=open("DomHelp.txt")
data=f.read()
c=0
for ch in data:
if ch in 'aeiou':
c+=1
print(c,'lowercase vowels in the file')
f.close()
SECTION D (4 X 4 = 16 Marks)
32. A) (4)
I. Select * from Dhelp order by Code;
II. Select Mobile from Dhelp where Gender='M' and age<30;
III. Select max(age), min(age) from dhelp;
IV. Select name from Dhelp where mobile is null;
OR
B)
I.
+--------+----------+
| gender | avg(age) |
+--------+----------+
| F | 30.5 |
| M | 30.0 |
+--------+----------+
II. +------+--------+
| Code | Name |
+------+--------+
| 8 | Chris |
| 4 | Sania |
| 6 | Ashish |
| 5 | Xavier |
+------+--------+
III. +------+--------+------+
| Code | Name | Age |
+------+--------+------+
| 2 | Basil | 28 |
| 8 | Chris | 32 |
| 6 | Ashish | 32 |
| 5 | Xavier | 28 |
+------+--------+------+
IV. +------------+
| count(age) |
+------------+
| 6 |
+------------+
34. (I) select name, mobile from dhelp,contract where Code=HCode and (4)
salary>11000;
(II) select contract.*, name from dhelp, contract
where Code=HCode and duration between 10 and 12;
(III) update contract set salary=salary+10/100*salary;
(IV) (A) select name, gender from dhelp, contract
where Code=HCode and startdate like '%-12-%';
OR
(B) alter table dhelp add primary key(code);
SECTION E (2 X 5 = 10 Marks)
Answer Key
Sample Question Paper-2 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. False (1)
5. (C) 1 3 (1)
6. [2, 4, 6, 8] (1)
9. False (1)
14. (A) Number of non null values in the House column. (1)
(II) A) print(S1.count('m'))
OR
B) print('-'.join(S1))
25. Correct possible output(s): (A) 1-2-1-0- and (B) 3-3-2-6- (2)
Minimum possible values of Pos is 3
Maximum possible values of Pos is 6
Section-C ( 3 x 3 = 9 Marks)
29. A) def vowelLines(): (3)
f=open("Juice.txt")
for line in f:
line=line[:-1] #to remove '\n' from the line
if line[-1] in 'aeiou':
print(line)
f.close()
OR
B)
def fiveLetterWords():
f=open("Juices.txt")
data=f.read()
words=data.split()
for w in words:
if len(w)==5:
print(w,end=' ')
f.close()
30. (A) (3)
def push_Juice(Juices, new_Juice):
Juices.append(new_Juice)
def pop_Juice(Juices):
if Juices:
return Juices.pop()
else: print("Underflow")
def peep(Juicetack):
if Juices:
print(Juices[-1])
else: print("None")
OR
(B)
import random
nums=[random.randint(10,99) for i in range(20)];
print(nums)
stack=[]
for n in nums:
if n%5==0:
stack.append(n)
while stack:
print(stack.pop(), end=' ')
print("Empty Stack")
31. A) {'T': 3, 'i': 1, 'c': 2, '-': 2, 'a': 1, 'o': 1, 'e': 1} (3)
OR
B) 3-5-3-5-3-1-
SECTION D (4 X 4 = 16 Marks)
32. Based on the table Drinks, as given below, answer part A to write the queries OR part B (4)
to write the output of the given queries.
Table: Drinks
+-------+------+-------+------------+
| Name | Size | Price | Remarks |
+-------+------+-------+------------+
| Apple | S | 0.75 | Apple Only |
| Apple | M | 1 | Apple Only |
| Apple | L | 1.5 | Apple Only |
| Mango | L | 2 | Shake |
| Mango | M | 1.5 | Shake |
| Mango | S | 0.75 | Mango Only |
+-------+------+-------+------------+
A)
I. select Name, avg(Price) from Drinks group by Name;
II. select * from Drinks where remarks='Shake';
III. select count(*) from Drinks where remarks like '%Only%';
IV. select * from Drinks where Price<1;
OR
B)
I. +-------+-------+
| name | price |
+-------+-------+
| Apple | 0.75 |
| Apple | 1 |
| Mango | 1.5 |
| Mango | 0.75 |
+-------+-------+
II. +------------+------------+
| min(price) | max(price) |
+------------+------------+
| 0.75 | 0.75 |
| 1 | 1.5 |
| 1.5 | 2 |
+------------+------------+
III. +------+
| size |
+------+
| S |
| M |
| L |
+------+
IV. +-------+------+-------+
| Name | Size | Price |
+-------+------+-------+
| Apple | M | 1 |
| Apple | L | 1.5 |
| Mango | M | 1.5 |
| Mango | L | 2 |
+-------+------+-------+
34. (I) select Juices.* from Juices natural join Orders; (4)
(II) Select Orders.*,Content from Juices natural join Orders
where O_date like '2024%';
(III) select O_No, O_Qty*Price*(100-Discount) as value from Juices
natural join orders;
(IV) (A) select J_ID, Price from Juices natural join orders
where discount=0 or discount is null;
OR
(B) alter table juices add column BalQty int(4);
conn=cnctr.connect(host='localhost', user='Guest',
password=' Abhi-J', database='AbhiSales')
crsr=conn.cursor()
ID=input("Enter J_ID to delete: ")
qry=f"delete from Juices where J_ID='{ID}'"
crsr.execute(qry)
conn.commit()
qry='select * from Juices'
crsr.execute(qry)
for rec in crsr:
print(rec)
SECTION E (2 X 5 = 10 Marks)
37. (I) Admin block. This is the most secured block as it has restricted public (5)
movement.
(II) Switch
(III)
Answer Key
Sample Question Paper-3 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. True (1)
2. (C) -1 (1)
3. True (1)
6. venddo (1)
7. dict.fromkeys(rec,10) (1)
9. True (1)
OR
B) S3=S2.rstrip()
(II)
A) print(sorted(S1))
OR
B) print(len(S2))
Section-C ( 3 x 3 = 9 Marks)
def Pop_Movies():
c=0
while Ratings:
print(Ratings.pop(), end=' ')
c+=1
else: print(c,"Records popped")
OR
(B) def Push(Color, S):
for clr in Color:
if len(clr)>5:
S.append(clr)
def Pop(S):
while S:
print(S.pop(), end=' ')
else: print("Stack Empty")
SECTION D (4 X 4 = 16 Marks)
32. A) (4)
I. Select Title from movies where Actor='Abhay Deol';
II. Select * from movies where year = 2012;
III. Select count(*) from movies where Music='M001';
IV. Select * from movies where Director='Prakash Jha';
OR
B)
I. +------+----------+
| Year | count(*) |
+------+----------+
| 2012 | 1 |
| 2013 | 1 |
| 2016 | 1 |
| 2019 | 1 |
| 2020 | 1 |
| 2021 | 1 |
+------+----------+
II. +-------+----------+
| Music | count(*) |
+-------+----------+
| M002 | 2 |
| M001 | 3 |
| M003 | 1 |
+-------+----------+
III. +-------+--------------+
| mid | title |
+-------+--------------+
| MV002 | Madras Cafe |
| MV003 | Jai Gangajal |
+-------+--------------+
IV. +-------+---------------+------+
| mid | title | year |
+-------+---------------+------+
| MV005 | Gulabo Sitabo | 2020 |
| MV002 | Madras Cafe | 2013 |
| MV006 | Sardar Udham | 2021 |
+-------+---------------+------+
34. (I) select MID,Musician.* from movies natural join musician where (4)
MID in ('MV001','MV002','MV006');
(II) select MID, Title, Name1 from movies natural join musician;
(III) delete from movies where year<2015;.
(IV) (A) alter table movies add primary key(MID);
OR
(B) alter table musician drop column movies;
SECTION E (2 X 5 = 10 Marks)
(IV) Firewall.
(V) (A) Data transfer over Wi-Fi is less secure than data transfer using cables?
OR
(B) Star.
Answer Key
Sample Question Paper-4 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. False (1)
3. True (1)
4. (B) 3 (1)
6. pePne* (1)
7. print(my_dict[1,2]) (1)
9. True (1)
17. (C) Infrared rays are used for short distance communication. (1)
22. title() turns the first letter of each word of the given string into uppercase and turns (2)
all other characters into lowercase.
capitalize() turns the first letter of the given string into uppercase and turns all other
characters into lowercase.
Output: A Bc De- A bc de
28. A) Bandwidth of a channel is the range of frequencies available for transmission of data (2)
The unit to measure bandwidth is Hertz (Hz).
OR
B) IP address, also known as Internet Protocol address, is a unique address that can be
used to uniquely identify each node in a network.
Example: 192:168:0:178
Section-C ( 3 x 3 = 9 Marks)
SECTION D (4 X 4 = 16 Marks)
32. A) (4)
I. Update teachers set Age=Age+1, Exp=Exp+1;
II. Select * from Teachers where SubCode='042' and DOJ like
'2022%';
III. Select Desig, min(Age), max(Age) from teachers group by
Desig;
IV. Select Name, Age, SubCode from Teachers where Desig='PGT'and
Exp>10;
OR
B)
I. +------------+------+
| Name | Exp |
+------------+------+
| Rashmi | 7 |
| Bharat | 9 |
| Damanpreet | 10 |
| Charu | 15 |
| Asim | 17 |
| David | 17 |
| Rajesh | 21 |
+------------+------+
II. +----------+
| count(*) |
+----------+
| 4 |
+----------+
III. +---------+----------+
| subcode | count(*) |
+---------+----------+
| 041 | 2 |
| 043 | 1 |
| 042 | 2 |
| 083 | 1 |
| 803 | 1 |
+---------+----------+
IV. +------------+------------+
| min(doj) | max(doj) |
+------------+------------+
| 2019-12-01 | 2022-12-11 |
+------------+------------+
SECTION E (2 X 5 = 10 Marks)
(III)
(IV) Firewall
(V) (A) No, as we are using Optical Fibre Cable
OR
(B) Star topology.
Answer Key
Sample Question Paper-5 (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
1. True (1)
2. (D) 9 (1)
3. '0' (1)
4. (B) 3 (1)
7. None (1)
9. False (1)
15. (B) same as the domain of the Primary key to which it refers. (1)
(II)
A) print(S2.count('a'))
OR
B) LS1=sorted(list(S1))
Section-C ( 3 x 3 = 9 Marks)
OR
B) def readTV():
with open('TV.txt') as f:
for line in f:
line=line.rstrip()
if line[-1] in '.,':
line=line[:-1]
print(line[0],line[-1])
OR
31. A) 5 2 (3)
4 1
1 4
OR
B) 21 15
7 15
15 7
SECTION D (4 X 4 = 16 Marks)
32. A) (4)
I. Update TV set price=price*95/100 where Brand='Sony';
II. Select * from TV where Resolution='4K';
III. Select Brand, count(*) from TV group by Brand;
IV. Delete from TV where Resolution is NULL;
OR
B)
I. +-------+------+
| Brand | Size |
+-------+------+
| Acer | 43 |
| Acer | 50 |
| LG | 32 |
+-------+------+
II. +---------+------+-------+
| Brand | Size | Price |
+---------+------+-------+
| Samsung | 65 | 68000 |
| LG | 32 | 14000 |
+---------+------+-------+
III. +------------+
| avg(price) |
+------------+
| 37333.3333 |
+------------+
IV. +----------+------+---------+
| Model | Size | Display |
+----------+------+---------+
| Bravia | 55 | LED |
| Bravia 2 | 43 | LED |
| Crystal | 65 | OLED |
+----------+------+---------+
34. (I) select TV.* from TV natural join Bills where BDate like (4)
'2024%';
(II) select Bills.* from TV natural join Bills where Brand='Sony';
(III) select BNo,T_ID from TV natural join Bills where Size<50;
(IV) (A) alter table TV add Primary key(T_ID);
OR
(B) alter table Bills add Cust int;
SECTION E (2 X 5 = 10 Marks)
37. (I) ADMIN building, as it has the maximum number of computers. (5)
(II)
(III) Suggest and draw the cable layout to efficiently connect various buildings within the
PATHANKOT campus for connecting the computers.
(IV) Firewall
(V) Video Conferencing
(VI) (A) Yes. Switches are needed in each building to interconnect the computers within
that building.
OR
(B) Yes. Router is needed to interconnect all the buildings and to provide Internet in
the campus.
Formatted Output
Absolute and Relative file paths
www.yogeshsir.com www.youtube.com/LearnWithYK