24. Evaluate the following expressions:
a) 6 * 3 + 4**2 // 5 – 8
Ans: 13
b) 10 > 5 and 7 > 12 or not 18 > 3
Ans: False
25. Differentiate between Viruses and Worms in context of networking and data communication threats.
Ans: Virus: A virus needs a host file or program to work. It spreads when the infected file is opened or executed.
Worm: A worm is a standalone program. It spreads automatically without needing any host file or user action.
OR
Differentiate between Web server and web browser. Write any two popular web browsers.
Ans: Web Browser: A web browser is a software application used to access and view websites on the internet. It requests web pages from a web server and displays them to the user.
Web Server: A web server is a computer or system that stores websites and delivers web pages to users when requested by a web browser using HTTP.
Popular Web Browsers are:
Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, etc.
26. Expand the following terms:
a. SMTP - Simple Mail Transfer Protocol
b. XML - eXtensible Markup Language
c. LAN - Local Area Network
d. IPR - Intellectual Property Rights
27. Differentiate between actual parameter(s) and a formal parameter(s) with a suitable example for each.
Ans: Actual Parameters (Arguments): These are the values, variables, or expressions passed to a function when it is called.
Formal Parameters: These are the variables defined in the function definition that receive values from actual parameters.
Example:
def area(side): # Formal parameter
return side * side
print(area(5)) # Actual parameter
Here, side is the formal parameter and value 5 is the actual parameter.
OR
Explain the use of global key word used in a function with the help of a suitable example.
Ans: In Python, the global keyword is used inside a function to modify a variable that is defined outside the function (global variable).
Normally, variables inside a function are local, but using global allows us to use and change the global variable.
Example:
c = 10 # global variable
def add():
global c
c = c + 2
print("Inside add():", c)
add()
c = 15
print("In main:", c)
Output:
Inside add(): 12
In main: 15
28. Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
Value=30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
Ans: Correted Code:
Value = 30
for VAL in range(0, Value): # missing colon
if VAL % 4 == 0: # If → if, val → VAL
print(VAL * 4)
elif VAL % 5 == 0: # Elseif → elif, val → VAL
print(VAL + 3)
else: # else missing colon
print(VAL + 10)
29. What possible outputs(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also specify the maximum values that can be assigned to each of the variables Lower and Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
a) 10#40#70#
b) 30#40#50#
c) 50#60#70#
d) 40#50#70#
30. What do you understand by Candidate Keys in a table? Give a suitable example of Candidate Keys from a table containing some meaningful data.
Ans:
Table: Item
| Ino |
Item |
Qty |
| I01 |
Pen |
500 |
| I02 |
Pencil |
700 |
| I04 |
CD |
500 |
| I09 |
|
700 |
| I05 |
Eraser |
300 |
| I03 |
Duster |
200 |
31. Differentiate between fetchone() and fetchall() methods with suitable examples for each.
Ans: fetchone()
It retrieves one row at a time from the query result.
It returns None when no more rows are available.
fetchall()
It retrieves all rows at once from the query result.
It returns an empty list [] if no records are found.
Example:
cursor.execute("SELECT * FROM student")
row = cursor.fetchone() # fetch one record
print(row)
rows = cursor.fetchall() # fetch all remaining records
print(rows)
32. Write the full forms of DDL and DML. Write any two commands of DML in SQL.
Ans: DDL - Data Definition Language
DML - Data Manipulation Language
Any two out of INSERT, DELETE, UPDATE
33. Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
print(m)
Display('Fun@Python3.0')
PART B: SECTION - II
34. Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list
Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
Ans:
def LShift(Arr, n):
L = len(Arr)
for x in range(0, n):
y = Arr[0]
for i in range(0, L-1):
Arr[i] = Arr[i+1]
Arr[L-1] = y
print(Arr)
35. Write a function in Python that counts the number of “Me” or “My” words present in a text file “STORY.TXT”.
If the “STORY.TXT” contents are as follows:
My first book was Me and My Family. It gave me chance to be Known to the world.
The output of the function should be:
Count of Me/My in file: 4
Ans:
def displayMeMy():
num = 0
f = open("STORY.TXT", "r")
data = f.read()
words = data.split()
for x in words:
if x.lower() == "me" or x.lower() == "my":
num = num + 1
f.close()
print("Count of Me/My in file:", num)
OR
Write a function AMCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurance of alphabets A and M (including small cases a and m too).
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The EUCount() function should display the output as:
A or a: 4
M or m: 2
Ans:
def AMCount():
f = open("STORY.TXT", "r")
A, M = 0, 0
data = f.read()
for x in data:
if x.lower() == "a":
A += 1
elif x.lower() == "m":
M += 1
f.close()
print("A or a:", A)
print("M or m:", M)
36. Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and Posting given below:
Table: TEACHER
| T_ID |
Name |
Age |
Department |
Date_of_join |
Salary |
Gender |
| 1 |
Jugal |
34 |
Computer Sc |
10/01/2017 |
12000 |
M |
| 2 |
Sharmila |
31 |
History |
24/03/2008 |
20000 |
F |
| 3 |
Sandeep |
32 |
Mathematics |
12/12/2016 |
30000 |
M |
| 4 |
Sangeeta |
35 |
History |
01/07/2015 |
40000 |
F |
| 5 |
Rakesh |
42 |
Mathematics |
05/09/2007 |
25000 |
M |
| 6 |
Shyam |
50 |
History |
27/06/2008 |
30000 |
M |
| 7 |
Shiv Om |
44 |
Computer Sc |
25/02/2017 |
21000 |
M |
| 8 |
Shalakha |
33 |
Mathematics |
31/07/2018 |
20000 |
F |
Table: POSTING
| P_ID |
Department |
Place |
| 1 |
History |
Agra |
| 2 |
Mathematics |
Raipur |
| 3 |
Computer Science |
Delhi |
i. SELECT Department, count(*) FROM Teacher GROUP BY Department;
Ans:
| Department |
Count(*) |
| History |
3 |
| Computer Sc |
2 |
| Mathematics |
3 |
ii. SELECT Max(Date_of_Join),Min(Date_of_Join) FROM Teacher;
Ans:
| Max(Date_of_Join) |
Min(Date_of_Join) |
| 31/07/2018 |
05/09/2007 |
iii. SELECT Teacher.name,Teacher.Department, Posting.Place FROM Teachr, Posting WHERE Teacher.Department = Posting.Department AND Posting.Place=”Delhi”;
Ans:
| Name |
Department |
Place |
| Jugal |
Computer Sc |
Delhi |
| Shiv Om |
Computer Sc |
Delhi |
37. Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message.
Ans:
def PUSH(Arr):
s = []
for x in Arr:
if x % 5 == 0:
s.append(x)
if len(s) == 0:
print("Empty Stack")
else:
print("Stack elements:", s)
OR
Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack.
Ans:
def POP(Arr):
if len(Arr) == 0:
print("Underflow")
return None
else:
val = Arr.pop()
return val
PART B: SECTION - III
38. MyPace University is setting up its academic blocks at Naya Raipur and is planning to set up a network. The University has 3 academic blocks and one Human Resource Center as shown in the diagram below:
Center to Center distances between various blocks/center is as follows:
| Law Block to Business Block |
40m |
| Law Block to Technology Block |
80m |
| Law Block to HR Center |
105m |
| Business Block to Technology Block |
30m |
| Business Block to HR Center |
35m |
| Technology Block to HR Center |
15m |
Number of computers in each of the blocks/Center is as follows:
| Law Block |
15 |
| Technology Block |
40 |
| HR center |
115 |
| Business Block |
25 |
a) Suggest the most suitable place (i.e., Block/Center) to install the server of this University with a suitable reason.
Ans: Most suitable place to install the server is HR center, as this center has maximum number of computers.
b) Suggest an ideal layout for connecting these blocks/centers for a wired connectivity.
Ans:
c) Which device will you suggest to be placed/installed in each of these blocks/centers to efficiently connect all the computers within these blocks/centers.
Ans: Switch
d) Suggest the placement of a Repeater in the network with justification.
Ans: Repeater may be placed when the distance between 2 buildings is more than 70 meter.
e) The university is planning to connect its admission office in Delhi, which is more than 1250km from university. Which type of network out of LAN, MAN, or WAN will be formed? Justify your answer.
Ans: WAN, as the given distance is more than the range of LAN and MAN.
39. Write SQL commands for the following queries (i) to (v) based on the relations Teacher and Posting given below:
Table: TEACHER
| T_ID |
Name |
Age |
Department |
Date_of_join |
Salary |
Gender |
| 1 |
Jugal |
34 |
Computer Sc |
10/01/2017 |
12000 |
M |
| 2 |
Sharmila |
31 |
History |
24/03/2008 |
20000 |
F |
| 3 |
Sandeep |
32 |
Mathematics |
12/12/2016 |
30000 |
M |
| 4 |
Sangeeta |
35 |
History |
01/07/2015 |
40000 |
F |
| 5 |
Rakesh |
42 |
Mathematics |
05/09/2007 |
25000 |
M |
| 6 |
Shyam |
50 |
History |
27/06/2008 |
30000 |
M |
| 7 |
Shiv Om |
44 |
Computer Sc |
25/02/2017 |
21000 |
M |
| 8 |
Shalakha |
33 |
Mathematics |
31/07/2018 |
20000 |
F |
Table: POSTING
| P_ID |
Department |
Place |
| 1 |
History |
Agra |
| 2 |
Mathematics |
Raipur |
| 3 |
Computer Science |
Delhi |
i. To show all information about the teacher of History department.
Ans: SELECT * FROM teacher WHERE department = 'History';
ii. To list the names of female teachers who are in Mathematics department.
Ans: SELECT name FROM teacher
WHERE department = 'Mathematics' AND gender = 'F';
iii. To list the names of all teachers with their date of joining in ascending order.
Ans: SELECT name FROM teacher
ORDER BY date_of_join;
iv. To display teacher’s name, salary, age for male teachers only.
Ans: SELECT name, salary, age FROM teacher
WHERE gender = 'M';
v. To display name, bonus for each teacher where bonus is 10% of salary.
Ans: SELECT name, salary * 0.1 AS Bonus FROM teacher;
40. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
i. Write a user defined function CreateFile() to input data for a record and add to Book.dat.
Ans:
import pickle
def CreateFile():
fobj = open("Book.dat", "ab")
BookNo = int(input("Book Number: "))
Book_Name = input("Book Name: ")
Author = input("Author: ")
Price = int(input("Price: "))
rec = [BookNo, Book_Name, Author, Price]
pickle.dump(rec, fobj)
fobj.close()
ii. Write a function CountRec(Author) in Python which accepts the Author name as parameter and count and return number of books by the given Author are stored in the binary file “Book.dat”
Ans:
import pickle
def CountRec(Author):
fobj = open("Book.dat", "rb")
num = 0
try:
while True:
rec = pickle.load(fobj)
if rec[2] == Author:
num += 1
except EOFError:
fobj.close()
return num
OR
A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write a function countrec() in Python that would read contents of the file “STUDENT.DAT” and display the details of those students whose percentage is above 75. Also display number of students scoring above 75%
Ans:
import pickle
def countrec():
fobj = open("STUDENT.DAT", "rb")
num = 0
try:
while True:
rec = pickle.load(fobj)
if rec[2] > 75:
print(rec[0], rec[1], rec[2], sep="\t")
num += 1
except EOFError:
fobj.close()
print("Number of students scoring above 75%:", num)
Download Now - Class 12 CS 083 Sample Question Paper 2020-21 with Solution