CBSE Class 12 CS 083 Sample QP 2023-24 (Additional) with Solution

Preparing for board exams becomes much easier with the right practice material, and the CBSE Class 12 Computer Science (083) Additional Sample Question Paper 2023-24 with Solution is a perfect resource for students. This sample paper is designed according to the latest CBSE syllabus and exam pattern, helping students understand the types of questions that can be asked in the final exam. It covers important topics like Python programming, data structures, SQL queries, and networking, ensuring complete revision in a structured way. Solving this paper not only improves problem-solving skills but also boosts confidence before the examination.

CBSE-Class-12-CS-083-Additional-Sample-Question-Paper-2023-24-with-Solution

Along with the Class 12 Computer Science Code 083 question paper, detailed solutions are provided to help students learn the correct approach to answering each question. These solutions are explained in a simple and easy-to-understand manner, making it beneficial for both self-study and classroom use. Teachers can also use this sample paper as a valuable teaching aid to guide students effectively. Regular practice with such additional sample papers helps in time management, accuracy, and better performance in the CBSE Class 12 Computer Science board exam.

CBSE Class 12 CS 083 Additional Sample QP 2023-24 with Solution

You can download the free PDF of this sample pre-board question paper from our website and start practicing today. Download Link available in last.

The Year-Wise CBSE Class 12 Computer Science (083) Pre-Board and Sample Question Papers with Solutions are provided at the bottom of this post.

CBSE Class 12 CS 083 Additional Sample Question Paper Session (2023-24)

CBSE | DEPARTMENT OF SKILL EDUCATION
COMPUTER SCIENCE (SUBJECT CODE - 083)
Sample Question Paper (SQP) Solution for Class XII (Session 2023-2024)

Max. Time: 3 Hours
Max. Marks: 70

General Instructions:
  1. Please check this question paper contains 35 questions.
  2. The paper is divided into 5 Sections- A, B, C, D and E.
  3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
  4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
  5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
  6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
  7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
  8. All programming questions are to be answered using Python Language only.
SECTION A (18 Marks)

1. Which of the following is an invalid identifier to be used in Python?
a) per%marks
b) _for
c) While
d) true

2. What is the correct way to add an element to the end of a list in Python?
a) list.add(element)
b) list.append(element)
c) list.insert(element)
d) list.extend(element)

3. What will be the output of
print("Welcome To My Blog"[2:6] + "Welcome To My Blog"[5:9])
a) Lcomme
b) lcomme T
c) lcomme To
d) lcomme

4. Which of the following statements is false?
a) A try-except block can have more than one except statement
b) One block of except statement cannot handle multiple exceptions
c) The finally block is always executed
d) When 1 == "1" is executed, no exception is raised

5. Which of the following statement(s) would give an error during the execution of the following code?
R = {'pno':52,'pname':'Virat', 'expert':['Badminton','Tennis'] ,'score':(77,44)}
print(R) #Statement 1
R['expert'][0]='Cricket' #Statement 2
R['score'][0]=50 #Statement 3
R['pno']=50 #Statement 4
a) Statement 1
b) Statement 2
c) Statement 3
d) Statement 4

6. Which pickle module method is used to write a Python object to a binary file?
a) save()
b) serialize()
c) store()
d) dump()

7. Given the following dictionaries
dict_student = {"rno" : "53", "name" : 'Rajveer Singh'}
dict_marks = {"Accts" : 87, "English" : 65}
Which statement will append the contents of dict_marks in dict_student?
a) dict_student + dict_marks
b) dict_student.add(dict_marks)
c) dict_student.merge(dict_marks)
d) dict_student.update(dict_marks)

8. Which of the following is not a component of the math module in Python?
a) ceil()
b) mean()
c) fabs()
d) pi

9. What will be the output of the following code?
L=["One , Two", "Three", "Four"]
print(len(L)/2*len(L[0]))
a) 6.5
b) 13
c) 13.5
d) 6.0

10. Expand the following terms:
(i) PPP - Point to Point Protocol
(ii) VoIP - Voice over Internet Protocol

11. Which SQL operator performs pattern matching?
a) BETWEEN operator
b) LIKE operator
c) EXISTS operator
d) =

12. Which Python function is used for displaying only one result set from SQL table in a database?
a) fetch1()
b) fetchno()
c) fetchall()
d) fetchone()

13. Which of the following file opening mode in Python, generates an error if the file does not exist?
a) a
b) r
c) w
d) w+

14. The correct syntax of seek() is:
a) file_object.seek(offset [, reference_point])
b) seek(offset [, reference_point])
c) seek(offset, file_object)
d) seek.file_object(offset)

15. Which of the following statements is false?
a) SMTP and POP protocols are used in email communication
b) URL of a page is not always the same as its domain name
c) HTTPS is safer than HTTP
d) Interlinking of collection of webpages is called Internet

16. Fill in the blank:
_______ protocol provides access to services hosted on a remote computer.
a) FTP
b) PPP
c) Telnet
d) SMTP

Q 17 and 18 are ASSERTION AND REASONING 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

17. Assertion (A): For changes made to a variable defined within a function to be visible outside the function, it should be declared as global.
Reason (R): Variables defined within a function are local to that function by default, unless explicitly specified with the global keyword.
Ans: a) Both A and R are true and R is the correct explanation for A

18. Assertion (A): A binary file in python is used to store collection objects like lists and dictionaries that can be later retrieved in their original form using pickle module.
Reason (R): Binary files are just like normal text files and can be read using a text editor like Notepad.
Ans: c) A is True but R is False

SECTION B (14 Marks)

19. Write two advantages and two disadvantages of circuit switching.
Ans: Advantages:
(i) A dedicated communication channel increases the quality of communication.
(ii) Suitable for long continuous communication.
Disadvantages:
(i) Resources are not utilized fully.
(ii) The time required to establish the physical link between the two stations is too long.

OR

Differentiate between Web server and web browser. Write the names of any two web browsers.
Ans: Web browser
Purpose: Receives and displays web content.
Function: Initiates requests to web servers, and receives and displays content for users.
Web server
Purpose: Delivers web content to clients.
Function: Listens to incoming requests, processes them, and sends requested content to the client.
Name of Web browsers: Google Chrome, Mozilla Firefox

20. Rewrite the following code in Python after removing all the syntax errors. Underline each correction done in the code.
num1, num2 = 10, 45
While num1 % num2 == 0
    num1 += 20
    num2 += 30
Else:
    print('hello')
Ans:
num1, num2 = 10, 45
while num1 % num2 = = 0:
    num1 += 20
    num2 += 30
else:
    print('hello')

21. Write a function dispBook(BOOKS) in Python, that takes a dictionary BOOKS as an argument and displays the names in uppercase of those books whose name starts with a consonant.
For example, Consider the following dictionary BOOKS = {1:"Python", 2:"Internet Fundamentals ", 3:"Networking ", 4:"Oracle sets", 5:"Understanding HTML"}
The output should be:
PYTHON
NETWORKING
Ans:
def dispBook(BOOKS):
    for key in BOOKS:
        if BOOKS[key][0] not in "AEIOUaeiou":
            print(BOOKS[key].upper())
BOOKS = {
    1: "Python",
    2: "Internet Fundamentals",
    3: "Networking",
    4: "Oracle sets",
    5: "Understanding HTML"
}
dispBook(BOOKS)

OR

Write a Python Program containing a function FindWord(STRING, SEARCH), that accepts two arguments : STRING and SEARCH, and prints the count of occurrence of SEARCH in STRING. Write appropriate statements to call the function.
For example, if STRING = "Learning history helps to know about history with interest in history" and SEARCH = 'history', the function should display
The word history occurs 3 times.
Ans:
def FindWord(STRING, SEARCH):
    return (STRING.count(SEARCH))
str = input('Enter String : ')
word = input('Enter word to search : ')
print('The word', word, 'occurs', FindWord(str, word), 'times')

22. What will be the output of the following code?
L = [5, 10, 15, 1]
G = 4
def Change(X):
    global G
    N = len(X)
    for i in range(N):
        X[i] += G
Change(L)
for i in L:
    print(i, end='$')
Ans: 9$14$19$5$

23. Write a suitable Python statement for each of the following tasks using built-in functions/methods only:
(i) To delete an element Mumbai:50 from Dictionary D.
Ans: del D['Mumbai']
(ii) To display words in a string S in the form of a list.
Ans: print(S.split())
OR
Write a Python Program to display alternate characters of a string my_str.
For example, if my_str = "Computer Science"
The output should be Cmue cec
Ans:
my_str = "Computer Science"
alternate_chars = my_str[::2]
print(alternate_chars)

24. Differentiate between % (percentage) and _(underscore) characters used with the LIKE operator in SQL with appropriate examples.
Ans:
Wildcard Description Example
% (Percentage) Matches any sequence of characters (including empty sequence). LIKE 'T%' matches all strings starting with 'T'. Even 'T' alone is included.
_ (Underscore) Matches a single character. LIKE '_ _T' matches any 3-letter string where the 3rd letter is 'T'.
OR

Differentiate between DROP and DELETE commands in SQL with appropriate examples.
Ans: DROP is a DDL command in SQL and can be used to remove tables (or database).
Example: 'DROP TABLE STUDENT;' will remove the table STUDENT from the database.
DELETE is a DML command used to remove or delete rows/records from a table.
Example: 'DELETE FROM STUDENT WHERE PER < 33;' will remove all those records from the table STUDENT where the percentage is less than 33.

25. Consider the following two commands with reference to a table, named Employee having a column named Department:
(a) Select count(Department) from Employee;
(b) Select count(*) from Employee;
If these two commands are producing different results,
(i) What may be the possible reason?
Ans: The difference occurs because COUNT(Department) counts only non-NULL values in the Department column, while COUNT(*) counts all rows in the table (including rows where Department is NULL).
So, if some employees have NULL (empty) values in the Department column, the results will differ.
(ii) Which command (a) or (b) might be giving a higher value?
Ans: (b) SELECT COUNT(*) FROM Employee;
Because it counts all records, including those where Department is NULL, so its value will always be greater than or equal to COUNT(Department).

SECTION C (15 Marks)

26. (a) Consider the table, BOOK and MEMBER given below:
TABLE : BOOK
CODE BNAME TYPE
F101 The priest Fiction
L102 Easy Python Programming
C101 Juman Ji Thriller
F102 Untold Story Fiction
C102 War Stories Comic
Table: MEMBER
MNO MNAME CODE ISSUEDATE
M101 SNEH SINHA L102 2022-10-13
M103 SARTHAK F102 2021-02-23
M102 SARA KHAN C101 2022-06-12
What will be the output of the following statement?
SELECT * FROM BOOK NATURAL JOIN MEMBER;
Ans:
CODE BNAME TYPE MNO MNAME ISSUEDATE
L102 Easy Python Programming M101 SNEH SINHA 2022-10-13
F102 Untold Story Fiction M103 SARTHAK 2021-02-23
C101 Juman Ji Thriller M102 SARA KHAN 2022-06-12
(b) Write the output of the queries (i) to (iv) based on the table
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;
Ans:
NAME PROJECT
Satyansh P04
Ranjan P01
Muneera P01
Alex P02
Akhtar P04
(ii) SELECT NAME, SALARY FROM EMPLOYEE WHERE NAME LIKE 'A%';
Ans:
NAME SALARY
Akhtar 125000
Alex 75000
(iii) SELECT NAME, DOJ FROM EMPLOYEE WHERE SALARY BETWEEN 100000 AND 200000;
Ans:
NAME DOJ
Ranjan 2015-01-21
Akhtar 2015-02-01
Muneera 2018-08-19
(iv) SELECT * FROM EMPLOYEE WHERE PROJECT = 'P01';
Ans:
Eid Name DOB DOJ Salary Project
E01 Rannja 1990-07-12 2015-01-21 150000 P01
E03 Muneera 1996-11-15 2018-08-19 135000 P01

27. (a) Consider the following tables – FACULTY and COURSES :
Table: FACULTY
FID FNAME LNAME JOINDATE SALARY
F01 Anishma Garg 2000-12-14 32000
F03 Bhumi Goel 2001-08-10 15000
F04 Neha Verma 2000-05-17 27000
F05 Meenu Sharma 2006-07-11 30000
Table: COURSES
C_ID FID CNAME FEES
C11 F01 Grid Computing 40000
C12 F04 Python 17000
C13 F03 C++ 8000
C14 F04 Computer Network 15000
C15 F01 HTML 12000
C16 F05 Data Science NULL
What will be the output of the following statement?
i SELECT FID, MIN(FEES), MAX(FEES) FROM COURSES GROUP BY FID;
Ans:
FID MIN(FEES) MAX(FEES)
F01 12000 40000
F04 15000 17000
F03 8000 8000
F05 NULL NULL
ii SELECT AVG(SALARY) FROM FACULTY WHERE FNAME LIKE '%a';
Ans:
AVG(SALARY)
29500
iii SELECT FNAME, CNAME FROM FACULTY F, COURSES C WHERE F.FID=C.FID AND COURSES.FID='F04';
Ans:
FNAME CNAME
Neha Python
Neha Computer Network
iv SELECT FNAME, CNAME , FEES FROM FACULTY F , COURSES C WHERE F.FID = C.FID AND FEE>15000;
Ans:
FNAME CNAME FEES
Anishma Grid Computing 40000
Neha Python 17000
(b) Write the name of the command to display the structure of a table in a database.
Ans: DESC or DESCRIBE command

28. Write a function COUNT() in Python to read from a text file 'Gratitude.txt' and display the count of the letter 'e' in each line
Example: If the file content is as follows:
Gratitude is a humble heart's radiant glow,
A timeless gift that nurtures and bestows.
It's the appreciation for the love we're shown,
In moments big and small, it's truly known.
The COUNT() function should display the output as:
Line 1 : 3
Line 2 : 4
Line 3 : 6
Line 4 : 1
Ans:
def Count():
    F = open('Gratitude.txt')
    T = F.readlines()
    X = 1
    for i in T:
        print('Line', X, ':', i.count('e'))
        X = X + 1
    F.close()
Count()

OR

Write a function Start_with_I() in Python, which should read a text file 'Gratitude.txt' and then display lines starting with 'I'.
Example: If the file content is as follows:
Gratitude is a humble heart's radiant glow,
A timeless gift that nurtures and bestows.
It's the appreciation for the love we're shown,
In moments big and small, it's truly known.
Then the output should be
It's the appreciation for the love we're shown,
In moments big and small, it's truly known.
Ans:
def Start_with_I():
    F = open('Gratitude.txt')
    T = F.readlines()
    for i in T:
        if i[0] in 'Ii':
            print(i, end='')
    F.close()
Start_with_I()


29. Navdeep creates a table RESULT with a set of records to maintain the marks secured by students in Sem1, Sem2, Sem3, and their divisions. After the creation of the table, he entered data of 7 students in the table.
ADNO ROLLNO SNAME SEM1 SEM2 DIVISION
123 101 KARAN 366 410 I
245 102 NAMAN 300 350 I
128 103 ISHA 400 410 I
129 104 RENU 350 357 I
234 105 ARPIT 100 75 IV
187 106 SABINA 100 205 II
181 107 NEELAM 470 450 I
Based on the data given above answer the following questions:
(i) Identify the columns which can be considered as candidate keys?
Ans: Candidate Keys : ADMNO, ROLLNO
(ii) If 2 more columns are added and 3 rows are deleted from the table result, what will be the new degree and cardinality of the above table?
Ans: Degree = 8, Cardinality = 4
(iii) Write a statement to increase the SEM2 marks by 3% for the students securing marks between 70 to 100.
Ans: Update result set SEM2=SEM2+.03*SEM2 where SEM2 between 70 and 100;

30. Given a Dictionary Stu_dict containing marks of students for three test-series in the form Stu_ID:(TS1, TS2, TS3) as key-value pairs.
Write a Python program with the following user-defined functions to perform the specified operations on a stack named Stu_Stk
(i) Push_elements(Stu_Stk, Stu_dict): It allows pushing IDs of those students, from the dictionary Stu_dict into the stack Stu_Stk, who have scored more than or equal to 80 marks in the TS3 Test.
(ii) Pop_elements(Stu_Stk): It removes all elements present inside the stack in LIFO order and prints them. Also, the function displays 'Stack Empty' when there are no elements in the stack.
Call both functions to execute queries.
For example:
If the dictionary Stu_dict contains the following data:
Stu_dict ={5:(87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,81,80), 18:(80,48,91)}
After executing Push_elements(), Stk_ID should contain [5,12,14,18]
After executing Pop_elements(), The output should be:
18
14
12
5
Stack Empty
Ans:
Stu_dict = {5:(87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,81,80), 18:(80,48,91)}
Stu_Stk=[]
def Push_elements(Stu_Stk, Stu_dict):
    for Stu_ID, marks in Stu_dict.items():
        if marks[2]>=80:
            Stu_Stk.append(Stu_ID)
def Pop_elements(Stu_Stk):
    while len(Stu_Stk)>0:
        print(Stu_Stk.pop())
    if not Stu_Stk:
        print('Stack Empty')
Push_elements(Stu_Stk, Stu_dict)
Pop_elements(Stu_Stk)

SECTION D (8 Marks)

31. Create a function maxsalary() in Python to read all the records from an already existing file record.csv which stores the records of various employees working in a department. Data is stored under various fields as shown below:
E_code E_name Scale Salary
A01 Bijesh Mehra S4 65400
B02 Vikram Goel S3 60000
C09 Suraj Mehta S2 45300
----- ----- ----- -----
Function should display the row where the salary is maximum.
Note: Assume that all employees have distinct salary.
Ans:
import csv
def maxsalary():
    f = open('record.csv', 'r')
    reader = csv.reader(f)
    skip_header = True
    max = 0
    for row in reader:
        if skip_header:
            skip_header = False
        else:
            if(int(row[3]) > max):
                max = int(row[3])
                rec = row
    print('Row with the highest salary : ', rec)
    f.close()
maxsalary()

32. Consider a binary file 'INVENTORY.DAT' that stores information about products using tuple with the structure (ProductID, ProductName, Quantity, Price). Write a Python function expensiveProducts() to read the contents of 'INVENTORY.DAT' and display details of products with a price higher than Rs. 1000. Additionally, calculate and display the total count of such expensive products.
For example: If the file stores the following data in binary format
(1, 'ABC', 100, 5000)
(2, 'DEF', 250, 1000)
(3, 'GHI', 300, 2000)
then the function should display
Product ID: 1
Product ID: 3
Total expensive products: 2
Ans:
import pickle
def expensiveProducts():
    with open('INVENTORY.DAT', 'rb') as file:
        expensive_count = 0
        while True:
            try:
                product_data = pickle.load(file)
                product_id, product_name, quantity, price = product_data
                if price > 1000:
                    print("Product ID:", product_id)
                    expensive_count += 1
            except EOFError:
                break
        print("Total expensive products: ", expensive_count)
expensiveProducts()

SECTION E (15 Marks)

33. Fun Media Services Ltd is an event planning organization. It is planning to set up its India campus in Mumbai with its head office in Delhi. The Mumbai campus will have four blocks/buildings - ADMIN, DECORATORS, FOOD, and MEDIA.
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.
CBSE-Class-12-CS-083-Additional-Sample-Question-Paper-2023-24-with-Solution-q33
Shortest distance between various buildings:
FROM – TO DISTANCE
ADMIN TO DECORATORS 90 meters
ADMIN TO MEDIA 75 meters
ADMIN TO FOOD 50 meters
DECORATORS TO FOOD 65 meters
DECORATORS TO MEDIA 50 meters
FOOD TO MEDIA 45 meters
DELHI Head Office to MUMBAI Campus 1475 KM
The number of computers at various buildings is as follows:
BUILDING NUMBER OF COMPUTERS
ADMIN 110
DECORATORS 75
MEDIA 12
FOOD 20
(i) Suggest the most appropriate location of the server inside the MUMBAI campus (out of the 4 buildings). Justify your answer.
Ans: The most appropriate location of the server inside the MUMBAI campus is ADMIN building due to the maximum number of computers in it.
(ii) Draw the cable layout to efficiently connect various buildings within the MUMBAI campus.
Ans: Cable Layout
CBSE-Class-12-CS-083-Additional-Sample-Question-Paper-2023-24-with-Solution-a33
(iii) Which hardware device will you suggest to connect all the computers within each building?
Ans: Switch or Hub
(iv) Which of the following will you suggest to establish online face-to-face communication between the people in the Admin Office of the MUMBAI campus and the DELHI Head Office?
a) Cable TV
b) Email
c) Video Conferencing
d) Text Chat
(v) What type of network (out of PAN, LAN, MAN, WAN) will be set up in each of the following cases?
(a) The Mumbai campus gets connected with the Head Quarter in Delhi
Ans: WAN
(b) The computers connected in the MUMBAI campus
Ans: LAN

34. (i) Mention any two differences between seek() and tell().
Ans:
seek() tell()
Purpose Repositions the file pointer to a specific location within a file Returns the current position of the file pointer
Syntax seek(offset [,reference point]) tell()
Parameters Requires specifying the offset and an optional reference point Requires no parameters
(ii) Consider a file FLIGHT.DAT containing multiple records. The structure of each record is as shown below:
[Fno, FName, Fare, Source, Destination]
Write a function COPY_REC() in Python that copies all those records from FLIGHT.DAT where the source is DELHI and the destination is MUMBAI, into a new file RECORD.DAT
Ans:
import pickle
def COPY_REC():
    In_file = open('FLIGHT.DAT', 'rb')
    out_file = open('RECORD.DAT', 'wb')
    try:
        while True:
            data = pickle.load(In_file)
            if data[3] == 'DELHI' and data[4] == 'MUMBAI':
                pickle.dump(data, out_file)
    except:
        In_file.close()
        out_file.close()
COPY_REC()

OR

(i) Mention any two differences between binary files and csv files?
Ans:
Binary CSV
1. pickle module to be used 1. csv module is used
2. Data is stored in binary format(0s and 1s) and is not in human readable form using any plain text editor. 2. Data is stored in tabular fashion and comma separated by default. The file can be read by any spreadsheet software or text editor.
3. File extension .dat/.pdf/.exe etc. 3. File extension .csv

(ii) Consider a Binary file BOOK.DAT containing a dictionary having multiple elements. Each element is in the form BNO:[BNAME,BTYPE,PRICE] as key:value pair
where
BNO - Book Number
BNAME - Book Name
BTYPE - Book Type
PRICE - Book price
Write a user-defined function, findBook(price), that accepts price as parameter and displays all those records from the binary file BOOK.DAT which has a book price more than or equal to the price value passed as a parameter.
Ans:
import pickle
def findBook(price):
    with open('BOOK.DAT', 'rb') as file:
        while True:
            try:
                book_record = pickle.load(file)
                for item in book_record:
                    book_price = book_record[item][2]
                    if book_price >= price:
                        print(item, book_record[item])
            except EOFError:
                break
findBook(50)

35. (i) Define the term constraint with respect to RDBMS. Give a suitable example.
Ans: A constraint in RDBMS is a rule applied on a table column to ensure the accuracy, validity, and integrity of data stored in the database.
Constraints restrict the type of data that can be inserted, updated, or deleted in a table.
Common Types of Constraints:
NOT NULL - Ensures that a column cannot store NULL values
UNIQUE - Ensures all values in a column are different
PRIMARY KEY - Uniquely identifies each record (combination of NOT NULL + UNIQUE)
FOREIGN KEY - Maintains relationship between two tables
CHECK - Ensures that values satisfy a specific condition
DEFAULT - Assigns a default value if no value is provided
Example:
CREATE TABLE Student (
    RollNo INT PRIMARY KEY,
    Name VARCHAR(50) NOT NULL,
    Age INT CHECK (Age >= 18),
    City VARCHAR(20) DEFAULT 'Ajmer'
);

(ii) Sameera maintains a database named STORE which contains a table named ITEM with the structure given below:
Ino (Item number) - integer
Iname (Item Name) - string
Price (Item Price) - float
Discount (Discount) - float
Note the following to establish connectivity between Python and MySQL:
Username - root
Password - tiger
Host - localhost
Help her to remove the record from the table ITEM for a particular value of item name input by the user.
import mysql.connector as mysql
con1 = mysql.connect(host='localhost', user='root', password='__', database='STORE')  # Statement-1
mycursor = ________  # Statement-2
item_name = input("Enter the Item name to remove the record : ")
query = ______________  # Statement-3
mycursor.execute(query)
con1.____  # Statement-4
print('Data Deleted successfully')
con1.close()
With reference to the above code, answer the following questions
(a) Complete statement 1 to establish the connection with the database.
Ans: password='tiger'
(b) Write statement 2 to create the cursor object.
Ans: mycursor = con1.cursor()
(c) Complete statement 3 to remove the record from the table ITEM based on the item name entered by the user
Ans: query = 'delete from ITEM where Iname = "{}" '.format.(item_name)
(d) Complete statement 4 to save the changes in the table.
Ans: con1.commit()

OR

i. Write one difference between the alternate key and the candidate key.
Ans: A candidate key is a column or a group of columns that can uniquely identify each record in a table. There can be more than one candidate key in a table.
An alternate key is a candidate key that is not chosen as the primary key.
ii. A table named ITEM is created in a database STORE. The table contains multiple columns whose details are as shown below:
Ino (Item number) - integer
Iname (Item Name) - string
Price (Item Price) - float
Discount (Discount) - float
Note the following to establish connectivity between Python and MySQL:
Username - root
Password - tiger
Host - localhost
However, the table is to be interfaced with Python to perform certain tasks. The incomplete code is given below:
______  # Line 1
con1 = mysql.connect(host='localhost', user='root', password='tiger', database='STORE')
mycursor = con1.______  # Line 2
query = 'SELECT * FROM ITEM where Price > {}'.format(______)  # Line 3
mycursor.execute(query)
data = mycursor.______  # Line 4
for rec in data:
    print(rec)
con1.close()
(a) Complete line 1 to import the appropriate module.
Ans: import mysql.connector as mysql
(b) Complete Line 2 to create the cursor object.
Ans: mycursor = con1.cursor()
(c) Complete the query given in Line 3 to display details of all such items from the table ITEMS whose price is more than 5000.
Ans: query = 'SELECT * FROM ITEM where Price > {}'.format(5000)
(d) Complete Line 4 to extract all the records.
Ans: data = mycursor.fetchall()

Download Now - Class 12 CS 083 Sample Question Paper 2023-24 (Additional) with Solution

download-class-12-cs-083-sample-pre-board-question-paper-with-solution

Year wise Pre-Board and CBSE Sample Question Papers with Solution – Class 12 Computer Science (Code 083)

CBSE Class 12 CS 083 Sample QP 2026-27 with Solution

CBSE Class 12 CS 083 Sample QP 2025-26 with Solution

CBSE Class 12 CS 083 Sample QP 2024-25 with Solution

CBSE Class 12 CS 083 Additional Sample QP 2023-24 with Solution

CBSE Class 12 CS 083 Sample QP 2023-24 with Solution

CBSE Class 12 CS 083 Sample QP 2022-23 with Solution

CBSE Class 12 CS 083 Sample QP 2021-22 Term 2 with Solution

CBSE Class 12 CS 083 Sample QP 2021-22 Term 1 with Solution

CBSE Class 12 CS 083 Sample QP 2020-21 with Solution

Post a Comment

Previous Post Next Post