Vikas Bharati Public School
Practical Examination Session(2024-2025)
Subject: Computer Science(083) SET A
Time: 3 Hr M.M : 30
Q1. Write a Python Program to read the text file Content.txt and display those words of each 4
line which start with any vowel character.
def display_vowel_words(file_name):
vowels = 'AEIOUaeiou'
file=open(file_name, 'r')
s=file.readlines()
for line in s:
words = line.split()
for word in words:
if word[0] in vowels:
print(word, end=" ")
print()
file.close()
display_vowel_words('Content.txt')
OR
Write function WritesStudent() to write the Records of Students (admno, name, fee) in a
binary file name “stud.dat”, and Write function Display( ) those records from a binary
which fee is less than 1500.
import pickle
def WritesStudent():
fp=open("stud.dat","ab")
admno=int(input("Enter the admission number"))
name=input("Enter the name")
fee=int(input("Enter the fee"))
l=[admno,name,fee]
pickle.dump(l,fp)
fp.close()
def Display():
fp=open("stud.dat","rb")
while True:
try:
l=pickle.load(fp)
if l[2]<1500:
print(l)
except EOFError:
break
fp.close()
while True:
print("1. Add records")
print("2. Display records")
print("3. Exit")
choice=int(input("Enter the choice"))
if choice==1:
WritesStudent()
elif choice==2:
Display()
else:
break
Q2 Create a python program to create a stack of student’s marks . 4
• Write function PUSH to add marks in to the stack and
• Write function POP to remove the marks from stack and display the same.
l=[]
def PUSH(m):
l.append(m)
def POP():
if len(l)==0:
print("Stack is empty")
else:
print(l.pop())
while True:
print("1. PUSH")
print("2. POP")
print("3. EXIT")
choice=int(input("Enter the choice"))
if choice==1:
m=int(input("Enter the marks"))
PUSH(m)
elif choice==2:
POP()
else:
break
Q3. Consider the following two tables Customer and Bill. Write SQL queries based on the two 4
tables.
Customer
CustomerID CustomerNam City MobileNo
e
C111 Abhishek Ahmedabad 9999999999
C132 Bhavik Anand 7799779977
C135 Chandani Baroda 8856895485
C145 Dhara Ahmedabad 7456879652
C121 Divya Anand 9015123569
Bill
OrderID OrderDate OrderAmt CustomerID
O111 2022-04-15 1500 C111
O112 2022-05-20 1800 C121
O113 2022-05-31 1000 C199
O131 2022-06-12 1400 C135
i.Display CustomerID, CustomerName, and bill amount for customers belonging to
Ahmedabad:
SELECT Customer.CustomerID, Customer.CustomerName, Bill.OrderAmt
FROM Customer
JOIN Bill ON Customer.CustomerID = Bill.CustomerID
WHERE Customer.City = 'Ahmedabad';
OR
SELECT A.CustomerID, A.CustomerName, B.OrderAmt
FROM Customer A, Bill B
WHERE A.CustomerID = B.CustomerID and A.City = 'Ahmedabad';
ii. Display the order details in descending order of amount:
SELECT * FROM Bill
ORDER BY OrderAmt DESC;
iii. Display OrderID, OrderDate, CustomerName, and MobileNo of customers whose
name ends with 'k' and contains the letter 'h'
SELECT Bill.OrderID, Bill.OrderDate, Customer.CustomerName, Customer.MobileNo
FROM Customer
JOIN Bill ON Customer.CustomerID = Bill.CustomerID
WHERE Customer.CustomerName LIKE '%h%k';
OR
SELECT OrderID, OrderDate, CustomerName, MobileNo
FROM Customer A, Bill B
WHERE A.CustomerID = B.CustomerID
AND CustomerName LIKE '%h%k';
iv. Display the sum of order amount for each city
SELECT City, SUM(OrderAmt) AS TotalOrderAmt
FROM Customer A, Bill B
WHERE A.CustomerID = B.CustomerID
GROUP BY City;
Q4. Report File 7
Q5. Project File 8
Q6. Viva 3
Vikas Bharati Public School
Practical Examination Session(2024-2025)
Subject: Computer Science(083) SET B
Time: 3 Hr M.M : 30
Q1. Write a function LShift(Arr, n) in Python, which accepts a list Arr of numbers and n is a numeric 4
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]
def LShift(Arr, n):
# Calculate the effective shift
n = n % len(Arr)
# Perform the left shift
shifted_arr = Arr[n:] + Arr[:n]
return shifted_arr
# Sample Input
Arr = [10, 20, 30, 40, 12, 11]
n=2
# Output
result = LShift(Arr, n)
print("Output:", result)
OR
Write a function to WriteRec() to write the 5 Employee Records (id, name, salary) in a binary file
name “Emp.dat” and ReadRec() function to read the all records from a binary file “Emp.dat” and
display them.
import pickle
def WriteRec():
employees = []
for i in range(5):
emp_id = input("Enter Employee ID: ")
emp_name = input("Enter Employee Name: ")
emp_salary = float(input("Enter Employee Salary: "))
employees.append((emp_id, emp_name, emp_salary))
with open('Emp.dat', 'ab') as file:
pickle.dump(employees, file)
print("Records written to Emp.dat")
def ReadRec():
try:
with open('Emp.dat', 'rb') as file:
employees = pickle.load(file)
for emp in employees:
print(emp)
except FileNotFoundError:
print("The file Emp.dat does not exist.")
while True:
print("1. Write Records to file")
print("2. Read Records from file")
print("3. Exit")
choice=int(input("Enter the choice"))
if choice==1:
WriteRec()
elif choice==2:
ReadRec()
else:
break
Q2 A list contains following record of a student: [StudentName, Class, Section, MobileNumber] 4
Write the following user defined functions to perform given operations on the stack named XII_A:
(i) pushElement() - To Push an object containing name and mobile number of students who
belong to class xii and section ‘a’ to the stack
(ii) popElement() - To Pop the objects from the stack and display them. Also, display “Stack
Empty” when there are no elements in the stack.
If the lists of students details are:
[“Rajveer”, “99999999999”,”XI”, “B”] [“Swatantra”, “8888888888”,”XII”, “A”]
[“Sajal”,”77777777777”,”VIII”,”A”] [“Yash”, “1010101010”,”XII”,”A”]
The stack XII_A should contain
[“Swatantra”, “8888888888” ] [“Yash”, “1010101010”]
The output should be:
[“Yash”, “1010101010”] [“Swatantra”, “8888888888”] Emtpy Stack
def pushElement(stack, student_list):
for student in student_list:
if student[2] == "XII" and student[3] == "A":
stack.append([student[0], student[1]])
def popElement(stack):
while stack:
print(stack.pop())
print("Stack Empty")
# Sample Input
students = [
["Rajveer", "99999999999", "XI", "B"],
["Swatantra", "8888888888", "XII", "A"],
["Sajal", "77777777777", "VIII", "A"],
["Yash", "1010101010", "XII", "A"]
]
# Create a stack
XII_A = []
# Push elements to the stack
pushElement(XII_A, students)
# Pop elements from the stack and display them
popElement(XII_A)
Q3. Consider the following two tables Student and Marks. Write SQL queries based on the two 4
tables.
Student
StudentI StudentName Class Age
D
S101 Ananya 10 15
S102 Rohan 11 16
S103 Meera 12 17
S104 Arjun 10 15
S105 Kavya 11 16
Marks
StudentI Subject Marks
D
S101 Math 85
S102 Science 90
S103 English 88
S104 Math 92
S105 Science 78
i. Display StudentID, StudentName, and Marks for students in Class 10
SELECT Student.StudentID, Student.StudentName, Marks.Marks
FROM Student, Marks
WHERE Student.StudentID = Marks.StudentID
AND Student.Class = 10;
ii. Display the details of students who scored more than 80 in Math
SELECT Student.StudentID, Student.StudentName, Marks.Marks
FROM Student, Marks
WHERE Student.StudentID = Marks.StudentID
AND Marks.Subject = 'Math'
AND Marks.Marks > 80;
iii. Increase the English marks by 3 for all students.
UPDATE Marks
SET Marks = Marks + 3
WHERE Subject = 'English';
iv. Display the average marks for each subject
SELECT Subject, AVG(Marks) AS AverageMarks
FROM Marks
GROUP BY Subject;
Q4. Report File 7
Q5. Project File 8
Q6. Viva 3
Vikas Bharati Public School
Practical Examination Session(2024-2025)
Subject: Computer Science(083) SET C
Time: 3 Hr M.M : 30
Q1. Write a program to read a list of n integers (positive as well as negative). Create two new lists, one 4
having all positive numbers and the other having all negative numbers from the given list. Print all
three lists
def separate_numbers(numbers):
positive_numbers = []
negative_numbers = []
for num in numbers:
if num >= 0:
positive_numbers.append(num)
else:
negative_numbers.append(num)
return positive_numbers, negative_numbers
# Read the list of integers from the user
numbers = list(eval(input("Enter the numbers separated by comma: ")))
# Separate the numbers into positive and negative lists
positive_numbers, negative_numbers = separate_numbers(numbers)
# Print all three lists
print("Original List:", numbers)
print("Positive Numbers:", positive_numbers)
print("Negative Numbers:", negative_numbers)
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%.
import pickle
def countrec():
try:
with open('STUDENT.DAT', 'rb') as file:
students = pickle.load(file)
count = 0
for student in students:
if student[2] > 75:
print(student)
count += 1
print("Number of students scoring above 75%:",count)
except FileNotFoundError:
print("The file STUDENT.DAT does not exist.")
# Example usage
students = [
[101, "Alice", 80],
[102, "Bob", 70],
[103, "Carol", 85],
[104, "Dave", 60],
[105, "Eve", 90]
]
# Writing the example data to the binary file for demonstration purposes
with open('STUDENT.DAT', 'wb') as file:
pickle.dump(students, file)
# Calling the function to read and display the records
countrec()
Q2 Vedika has created a dictionary containing names and marks as key-value pairs of 5 students. Write 4
a program, with separate user-defined functions to perform the following operations:
i. Push the keys (name of the student) of the dictionary into a stack, where the corresponding
value (marks) is greater than 70.
ii. Pop and display the content of the stack.
def pushElement(stack, student_dict):
for name, marks in student_dict.items():
if marks > 70:
stack.append(name)
def popElement(stack):
while stack:
print(stack.pop())
print("Stack Empty")
# Sample dictionary of students
students = {
"Vedika": 85,
"Raj": 65,
"Ananya": 75,
"Rohan": 55,
"Meera": 90
}
# Create a stack
XII_A = []
# Push elements to the stack
pushElement(XII_A, students)
# Pop elements from the stack and display them
popElement(XII_A)
Q3. Consider the following two tables Students and Courses. Write SQL queries based on the 4
two tables.
students
student_id student_nam age course_id
e
1 Alice 20 201
2 Bob 22 202
3 Carol 21 201
4 Dave 23 203
courses
course_i course_name
d
201 Mathematics
202 Physics
203 Computer Science
i. Write a query to display the student names along with their course names.
SELECT students.student_name, courses.course_name
FROM students
JOIN courses ON students.course_id = courses.course_id;
OR
SELECT A.student_name, B.course_name
FROM students A, courses B
WHERE A.course_id = B.course_id;
ii. Write a query to add a new column grade to the students table.
ALTER TABLE students
ADD COLUMN grade CHAR(1);
iii. Write a query to display all students who are enrolled in the 'Physics' course.
SELECT A.student_name
FROM students A, courses B
WHERE A.course_id = B.course_id
AND B.course_name = 'Physics';
iv. Write a query to increase the age of all students in the 201 course by 1 year.
UPDATE students
SET age = age + 1
WHERE course_id=201;
Q4. Report File 7
Q5. Project File 8
Q6. Viva 3
Vikas Bharati Public School
Practical Examination Session(2024-2025)
Subject: Computer Science(083) SET D
Time: 3 Hr M.M : 30
Q1. Write a program to write data into binary file marks.dat and display the records of students who 4
scored more than 95 marks.
import pickle
def write_data():
with open('marks.dat', 'ab') as file:
while True:
admission_number = input("Enter Admission Number: ")
name = input("Enter Name: ")
percentage = float(input("Enter Percentage: "))
student = [admission_number, name, percentage]
pickle.dump(student, file)
ans= input("Do you want to add another record? (y/n): ")
if ans.lower() != 'y':
break
def display_high_scorers():
try:
with open('marks.dat', 'rb') as file:
count = 0
while True:
try:
student = pickle.load(file)
if student[2] > 95:
print(student)
count += 1
except EOFError:
break
print("Number of students scoring above 95%:",count)
except FileNotFoundError:
print("The file marks.dat does not exist.")
while True:
print("\nMenu:")
print("1. Add Student Records")
print("2. Display High Scorers")
print("3. Exit")
choice = input("Enter your choice (1-3): ")
if choice == '1':
write_data()
elif choice == '2':
display_high_scorers()
elif choice == '3':
break
else:
print("Invalid choice. Please try again.")
OR
Write function AddDrug() to write the Records of Drug(DrugId, Name, Price) in a binary file name
“drug.dat”, and Write a function Display() to show those records from a binary which price is less
than 50.
import pickle
def AddDrug():
with open('drug.dat', 'ab') as file:
while True:
drug_id = input("Enter Drug ID: ")
name = input("Enter Drug Name: ")
price = float(input("Enter Drug Price: "))
drug = [drug_id, name, price]
pickle.dump(drug, file)
ans = input("Do you want to add another record? (y/n): ")
if ans.lower() != 'y':
break
def Display():
try:
with open('drug.dat', 'rb') as file:
while True:
try:
drug = pickle.load(file)
if drug[2] < 50:
print(drug)
except EOFError:
break
except FileNotFoundError:
print("The file drug.dat does not exist.")
# Example usage
AddDrug()
Display()
Q2 ICC has created a list in list containing top players and their runs as key value pairs of cricket team. 4
Write a program, with separate user defined functions to perform the following operations:
i. Push the keys (name of the players) of the list in list into a stack, where the corresponding
value (runs) is greater than 59.
ii. Pop and display the content of the stack.
For example:
If the sample content of the list in list is as follows:
SCORE=[name,runs]
SCORE=[["Mukesh",43],["Virendra",64],["Rajesh",88],["Amit",75],["Wajid",97] ]
The output from the program should be:Virendra Rajesh Amit Wajid
def pushElement(stack, score_list):
for player in score_list:
if player[1] > 59:
stack.append(player[0])
def popElement(stack):
while stack:
print(stack.pop())
print("Stack Empty")
# Sample list of players and their runs
SCORE = [["Mukesh", 43], ["Virendra", 64], ["Rajesh", 88], ["Amit", 75], ["Wajid", 97]]
# Create a stack
stack = []
# Push elements to the stack
pushElement(stack, SCORE)
# Pop elements from the stack and display them
popElement(stack)
Q3. Consider the following two tables employees and departments. Write SQL queries based 4
on the two tables.
employees
emp_i emp_name emp_ag dept_id
d e
1 John 30 101
2 Jane 25 102
3 Mike 35 101
4 Emma 28 103
departments
dept_i dept_name
d
101 Human Resources
102 Finance
103 IT
i. Write a query to display the total number of employees in each department.
SELECT B.dept_name, COUNT(A.emp_id) AS “total_employees”
FROM employees A, departments B
WHERE A.dept_id = B.dept_id
GROUP BY B.dept_name;
ii. Write a query to display the names of employees who are older than 30 and their
department names.
SELECT A.emp_name, B.dept_name
FROM employees A, departments B
WHERE A.dept_id = B.dept_id
AND A.emp_age > 30;
iii. Write a query to update the name of the department with dept_id 103 to
'Information Technology'.
UPDATE departments
SET dept_name = 'Information Technology'
WHERE dept_id = 103;
iv. Write a query to drop the emp_age column from the employees table.
ALTER TABLE employees
DROP COLUMN emp_age;
Q4. Report File 7
Q5. Project File 8
Q6. Viva 3