Set 1 Q1
import pickle
def add_record():
with open("[Link]", "ab") as file:
sid = int(input("Enter Shoe ID: "))
name = input("Enter Shoe Name: ")
brand = input("Enter Shoe Brand: ")
shoe_type = input("Enter Shoe Type: ")
price = float(input("Enter Shoe Price: "))
record = [sid, name, brand, shoe_type, price]
[Link](record, file)
print("Record added successfully.")
def display_records():
try:
with open("[Link]", "rb") as file:
print("Shoe Records:")
while True:
record = [Link](file)
print(record)
except EOFError:
pass
except FileNotFoundError:
print("File not found.")
def search_record(sid):
found = False
try:
with open("[Link]", "rb") as file:
while True:
record = [Link](file)
if record[0] == sid:
print("Record Found:", record)
found = True
break
except EOFError:
if not found:
print("Record not found.")
except FileNotFoundError:
print("File not found.")
while True:
print("\nMenu:\n1. Add record\n2. Display records\n3. Search record\n4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
add_record()
elif choice == 2:
display_records()
elif choice == 3:
sid = int(input("Enter Shoe ID to search: "))
search_record(sid)
elif choice == 4:
break
else:
print("Invalid choice. Try again.")
Set 1 q2
mysql> CREATE TABLE Teacher (
-> TeacherID INT PRIMARY KEY,
-> Tname VARCHAR(50) NOT NULL,
-> Department VARCHAR(50),
-> DOJ DATE,
-> Salary INT,
-> Gender CHAR(1)
-> );
mysql> INSERT INTO Teacher (TeacherID, Tname, Department, DOJ, Salary, Gender) VALUES
-> (101, 'Reena', 'Computer', '2019-01-02', 30000, 'F'),
-> (102, 'Mahima', 'History', '2014-05-12', 45000, 'F'),
-> (103, 'Rahul', 'Computer', '2009-01-01', 80000, 'M'),
-> (104, 'Mohit', 'Math', '2016-02-01', 40000, 'M'),
-> (105, 'Reema', 'History', '2014-02-02', 45000, 'F');
[Link] the number of male and female teachers:
SELECT Gender, COUNT(*) AS Total FROM Teacher GROUP BY Gender;
[Link] TeacherID and Tname working in Computer Department:
SELECT TeacherID, Tname FROM Teacher WHERE Department = 'Computer';
[Link] Tname, DOJ, and Gender where Salary is less than 45000:
SELECT Tname, DOJ, Gender FROM Teacher WHERE Salary < 45000;
4. Display the number of Teachers Department-wise:
SELECT Department, COUNT(*) AS Total FROM Teacher GROUP BY Department;
--------------------------------------------------------------------------------------------------------------------------------
set2 q1
stack = []
def push(element):
[Link](element)
print(f"{element} pushed to stac
def pop():
if stack:
print(f"{[Link]()} popped from stack.")
else:
print("Stack is empty.")
def display():
print("Stack contents:", stack)
while True:
print("\nMenu:\n1. Push\n2. Pop\n3. Display\n4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
element = input("Enter element to push: ")
push(element)
elif choice == 2:
pop()
elif choice == 3:
display()
elif choice == 4:
break
else:
print("Invalid choice. Try again.")
set2 q2
mysql> CREATE TABLE Garment (
-> Gcode INT PRIMARY KEY,
-> Gamename VARCHAR(50) NOT NULL,
-> Type VARCHAR(20),
-> Number INT,
-> Prizemoney INT,
-> ScheduleDate DATE
-> );
mysql> INSERT INTO Garment (Gcode, Gamename, Type, Number, Prizemoney, ScheduleDate)
VALUES
-> (101, 'Carom Board', 'Indoor', 2, 5000, '2004-01-23'),
-> (102, 'Badminton', 'Outdoor', 2, 12000, '2003-12-12'),
-> (103, 'Table Tennis', 'Indoor', 4, 8000, '2004-02-14'),
-> (105, 'Chess', 'Indoor', 2, 9000, '2004-01-01'),
-> (108, 'Lawn Tennis', 'Outdoor', 4, 25000, '2004-03-19');
1. Display the names of all games with their type:
SELECT Gamename, Type FROM Garment;
2. Display details of games with Prize money more than 5000:
SELECT * FROM Garment WHERE Prizemoney > 5000;
3. Display the content of the Games table in descending order of ScheduleDate:
SELECT * FROM Garment ORDER BY ScheduleDate DESC;
4. Count the number of games of each type:
SELECT Type, COUNT(*) AS Total FROM Garment GROUP BY Type;
---------------------------------------------------------------------------------------------------------------------
set3 q1
import pickle
dict1 = {'Python': 90, 'Java': 95, 'C++': 85}
with open("[Link]", "wb") as file:
[Link](dict1, file)
print("Dictionary written to binary file.")
with open("[Link]", "rb") as file:
data = [Link](file)
print("Dictionary read from binary file:", data)
set3q2
mysql> CREATE TABLE Hospital (
-> NO INT PRIMARY KEY,
-> NAME VARCHAR(50) NOT NULL,
-> AGE INT,
-> DEPARTMENT VARCHAR(50),
-> DATEOFADM DATE,
-> CHARGES INT,
-> SEX CHAR(1)
-> );
mysql> INSERT INTO Hospital (NO, NAME, AGE, DEPARTMENT, DATEOFADM, CHARGES, SEX) VALUES
-> (1, 'Arpan', 62, 'Surgery', '1998-01-21', 300, 'M'),
-> (2, 'Kareena', 32, 'Orthopaedic', '1998-02-19', 200, 'M'),
-> (3, 'Arun', 12, 'Surgery', '1998-01-11', 300, 'M'),
-> (4, 'Ketaki', 16, 'Ent', '1998-02-24', 250, 'F'),
-> (5, 'Ankita', 29, 'Cardiology', '1998-02-20', 800, 'F');
[Link] Patient's Name, Charges, and Age of only female patients:
SELECT NAME, CHARGES, AGE FROM Hospital WHERE SEX = 'F';
2. Find the total number of patients:
SELECT COUNT(*) AS TotalPatients FROM Hospital;
3. Find the department name and total number of patients in each department:
SELECT DEPARTMENT, COUNT(*) AS TotalPatients FROM Hospital GROUP BY DEPARTMENT;
4. Find the names of female patients whose department name ends with 'y':
SELECT NAME FROM Hospital WHERE SEX = 'F' AND DEPARTMENT LIKE '%y';