Set A
1. # Stack implementation using a list
def push(stack, element):
stack.append(element)
print(f"{element} pushed onto the stack.")
def pop(stack):
if not stack:
print("Stack is empty! Nothing to pop.")
else:
print(f"Popped element: {stack.pop()}")
def display(stack):
if not stack:
print("Stack is empty!")
else:
print("Stack elements are:")
for element in reversed(stack):
print(element)
def main():
stack = []
while True:
print("\nMenu:")
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
element = input("Enter the element to push: ")
push(stack, element)
elif choice == "2":
pop(stack)
elif choice == "3":
display(stack)
elif choice == "4":
print("Exiting the program.")
break
else:
print("Invalid choice! Please try again.")
if _name_ == "_main_":
main()
2. SQL Commands:
(i) To display details of those Faculties whose salary is greater
than 12000:
SELECT * FROM FACULTY WHERE Salary > 12000;
(ii) To display the details of courses whose fees is in the range of
15000 to 50000 (both values included):
SELECT * FROM COURSES WHERE Fees BETWEEN 15000
AND 50000;
(iii) To increase the fees of all courses by 500 of "System Design"
Course:
UPDATE COURSES SET Fees = Fees + 500 WHERE Cname =
'System Design';
(iv) To display the record of all the faculties according to their
salary in descending order:
SELECT F_ID, Fname, Lname, Hire_date FROM FACULTY
ORDER BY Salary DESC;
Set B
1. ‘’’Program to create a binary file with name and rollno.
and display them.’’’
import pickle
# Function to create and write to the binary file
def create_file(filename):
with open(filename, 'wb') as file:
n = int(input("Enter the number of students: "))
data = []
for _ in range(n):
rollno = input("Enter roll number: ")
name = input("Enter name: ")
data.append({'rollno': rollno, 'name': name})
pickle.dump(data, file)
print(f"Data successfully written to {filename}.")
# Function to search for a student by roll number
def search_file(filename, rollno):
try:
with open(filename, 'rb') as file:
data = pickle.load(file)
for record in data:
if record['rollno'] == rollno:
print(f"Student Found: Name = {record['name']},
Roll No = {record['rollno']}")
return
print("Roll number not found.")
except FileNotFoundError:
print(f"File {filename} not found.")
except EOFError:
print("File is empty.")
def main():
filename = "students.dat"
while True:
print("\nMenu:")
print("1. Create File")
print("2. Search Roll Number")
print("3. Exit")
choice = input("Enter your choice (1-3): ")
if choice == "1":
create_file(filename)
elif choice == "2":
rollno = input("Enter roll number to search: ")
search_file(filename, rollno)
elif choice == "3":
print("Exiting the program.")
break
else:
print("Invalid choice! Please try again.")
if _name_ == "_main_":
main()
2. SQL Commands:
(i) To display details of those Faculties whose salary is less than
12000:
SELECT * FROM FACULTY WHERE Salary < 12000;
(ii) To display the details of courses whose fees is in the range of
15000 to 50000 (both values included):
SELECT * FROM COURSES WHERE Fees BETWEEN 15000
AND 50000;
(iii) To increase the fees of all courses by 500 of "System Design"
Course:
UPDATE COURSES SET Fees = Fees + 500 WHERE Cname =
'System Design';
(iv) To display the name of all the faculties according to their
salary in ascending order:
SELECT Fname, Lname FROM FACULTY ORDER BY Salary
ASC;