Page 27 - PYTHON-12
P. 27
values = (mid, nm, gr, year, rating)
mycur.execute(query, values)
mydb.commit()
mycur.execute("select * from movies where rating>7.5")
for rec in mycur:
print(rec)
AddAndDisplay()
Section E
36. Hitesh wants to manage the records of the faculty members in his university. For this, he wants the following
information of each faculty member to be stored: (5)
• Faculty_ID – integer
• Faculty_Name – string
• Department – string
• Years_of_Service – integer
As a programmer, you have been assigned to do this job for Hitesh.
(I) Write a function to input the data of a faculty member and append it in a binary file.
(II) Write a function to update the Department to ‘Senior Faculty’ for all faculty members with more than
15 years of service.
(III) Write a function to read the data from the binary file and display the data of all those faculty members
who are not in ‘Senior Faculty’ department.
Ans. (I) import pickle
def input_faculty():
faculty = []
n = int(input("Enter the number of faculty members you want to
add: "))
for i in range(n):
faculty_id = int(input("Enter Faculty ID: "))
faculty_name = input("Enter Faculty Name: ")
department = input("Enter Department of faculty: ")
yearofservice = float(input("Enter years of service: "))
faculty.append([faculty_id, faculty_name,
department,yearofservice])
return faculty
faculty_list = input_faculty()
def append_faculty_data(faculty):
with open('FacultyMembers.bin', 'ab') as f:
for i in faculty:
pickle.dump(faculty, f)
print("Faculty members data appended successfully.")
append_faculty_data(faculty_list)
(II) import pickle
def update_senior_faculty():
updated_faculty = []
try:
Model Test Paper (Solved) A.13