Set 1:
1.
import pickle
# Function to create binary file
def create_file():
f = open("[Link]", "ab")
n = int(input("Enter number of records: "))
for i in range(n):
name = input("Enter name: ")
roll = int(input("Enter roll number: "))
record = [name, roll]
[Link](record, f)
[Link]()
# Function to search roll number
def search_roll():
f = open("[Link]", "rb")
r = int(input("Enter roll number to search: "))
found = False
try:
while True:
record = [Link](f)
if record[1] == r:
print("Name:", record[0])
found = True
break
except EOFError:
pass
if not found:
print("Record not found")
[Link]()
# Main program
create_file()
search_roll()
Set 1:
2.
(i) Display Name, Age and DOA for the students belonging to HISTORY department
SELECT Name, Age, DOA
FROM STUDENT
WHERE Dept = 'HISTORY';
(ii) Display the details in the descending order of Name
SELECT *
FROM STUDENT
ORDER BY Name DESC;
(iii) Display the sum of Fees for each department
SELECT Dept, SUM(Fees)
FROM STUDENT
GROUP BY Dept;
(iv) List student details whose names end with the letter 'n'
SELECT *
FROM STUDENT
WHERE Name LIKE '%n';
Set 2:
1.
stack = []
def push():
item = int(input("Enter element to push: "))
[Link](item)
print("Element pushed")
def pop():
if stack == []:
print("Stack is empty")
else:
print("Popped element:", [Link]())
def peek():
if stack == []:
print("Stack is empty")
else:
print("Top element:", stack[-1])
def display():
if stack == []:
print("Stack is empty")
else:
print("Stack elements:")
for i in reversed(stack):
print(i)
while True:
print("\n--- STACK MENU ---")
print("1. Push")
print("2. Pop")
print("3. Peek")
print("4. Display")
print("5. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
push()
elif ch == 2:
pop()
elif ch == 3:
peek()
elif ch == 4:
display()
elif ch == 5:
break
else:
print("Invalid choice")
Set 2:
2.
(i) Add primary key in table BOOKS using ALTER command
ALTER TABLE BOOKS
ADD PRIMARY KEY (BookID);
(ii) Increase the price of all computer books by 70
UPDATE BOOKS
SET Price = Price + 70
WHERE Category = 'Computer';
(iii) Display the Book ID, Book Name and Quantity Issued for all issued books
SELECT BookID, BookName, QuantityIssued
FROM BOOKS
WHERE QuantityIssued > 0;
(iv) Display Book ID, Book Name, Author Name and Quantity Issued for books with price
between 200 and 400
SELECT BookID, BookName, AuthorName, QuantityIssued
FROM BOOKS
WHERE Price BETWEEN 200 AND 400;
Set 3:
1.
import csv
# Function to create CSV file
def create_file():
f = open("[Link]", "w", newline='')
writer = [Link](f)
[Link](["UserID", "Password"])
n = int(input("Enter number of users: "))
for i in range(n):
uid = input("Enter User ID: ")
pwd = input("Enter Password: ")
[Link]([uid, pwd])
[Link]()
print("CSV file created successfully")
# Function to search password for given user-id
def search_password():
uid = input("Enter User ID to search: ")
found = False
f = open("[Link]", "r")
reader = [Link](f)
next(reader) # skip header
for row in reader:
if row[0] == uid:
print("Password:", row[1])
found = True
break
if not found:
print("User ID not found")
[Link]()
# Main program
create_file()
search_password()
Set 3:
2.
i) Display the name of all games with their Gcode
SELECT Gname, Gcode
FROM CLUB;
ii) Display details of games having fees more than 7000
SELECT *
FROM CLUB
WHERE Fees > 7000;
iii) Display the player name and his game with respect to Gcode
SELECT MemberName, Gname
FROM MEMBER, CLUB
WHERE [Link] = [Link];
iv) Output for:
SELECT COUNT(DISTINCT Number) FROM CLUB;
v) Output for:
SELECT DISTINCT GCODE FROM MEMBER;
Set 4:
1.
# Function to write data into the file
def write():
f = open("[Link]", "w")
[Link]("Whose woods these are I think I know.\n")
[Link]("His house is in the village though;\n")
[Link]("He will not see me stopping here\n")
[Link]("To watch his woods fill up with snow.")
[Link]()
# Function to count lines starting with 'H'
def countH():
f = open("[Link]", "r")
count = 0
for line in f:
if [Link]('H'):
count += 1
[Link]()
print("The line count should be", count)
# Calling functions
write()
countH()
Set 4:
2.
a) To display the name of all employees who are in the area of South
SELECT Name
FROM EMPLOYEE
WHERE Area = 'south';
b) To display the name and age of all employees whose age is greater than 40
SELECT Name, Age
FROM EMPLOYEE
WHERE Age > 40;
c) To increase the salary of female staff by 2%
UPDATE EMPLOYEE
SET Salary = Salary + (Salary * 0.02)
WHERE Sex = 'F';
d) To delete Sandeep’s record
DELETE FROM EMPLOYEE
WHERE Name = 'Sandeep';
Set 5:
1.
import csv
# Create CSV file
def create():
n = int(input("No. of books: "))
books = []
for i in range(n):
bid = input("Book ID: ")
name = input("Book Name: ")
price = input("Price: ")
[Link]([bid, name, price])
f = open("[Link]", "w", newline="")
w = [Link](f)
[Link](books)
[Link]()
# Search book by name
def search():
name = input("Enter book name: ")
f = open("[Link]", "r")
r = [Link](f)
for row in r:
if row[1].lower() == [Link]():
print(row)
break
else:
print("Book not found")
[Link]()
# Menu
while True:
print("[Link] [Link] [Link]")
ch = int(input())
if ch == 1:
create()
elif ch == 2:
search()
else:
break
Set 5:
2.
(i) Display Name, Age and DOA for students belonging to HINDI department
SELECT Name, Age, DOA
FROM STUDENT
WHERE Dept = 'HINDI';
(ii) Display details in ascending order of Age
SELECT *
FROM STUDENT
ORDER BY Age ASC;
(iii) Display the sum of Fees paid gender-wise
SELECT Gender, SUM(Fees)
FROM STUDENT
GROUP BY Gender;
(iv) List student details whose names start with the letter 'A'
SELECT *
FROM STUDENT
WHERE Name LIKE 'A%';
Set 6 :
1.
import pickle
def Add():
f = open("[Link]", "ab")
name = input("Enter animal name: ")
atype = input("Enter animal type: ")
food = input("Enter animal food: ")
record = [name, atype, food]
[Link](record, f)
[Link]()
def Search():
f = open("[Link]", "rb")
try:
while True:
record = [Link](f)
if record[2].lower() == "grass":
print(record[0])
except EOFError:
[Link]()
# Calling functions
Add()
Search()
Set 6:
2.
(a) To display the name of all employees who are in the area of South
SELECT Name FROM EMPLOYEE
WHERE Area = 'South';
(b) To display the name and age of all employees whose age is greater than 40
SELECT Name, Age FROM EMPLOYEE
WHERE Age > 40;
(c) To increase the salary of female staff by 2%
UPDATE EMPLOYEE
SET Salary = Salary + (Salary * 0.02)
WHERE Sex = 'F';
(d) To delete Sandeep's record
DELETE FROM EMPLOYEE
WHERE Name = 'Sandeep';