Page 13 - PYTHON-12
P. 13
Section E
36. Shreya is a manager working in Le Hotels Group of J&G industry. She needs to manage the records of various
hotels. For this, she wants the following information of each hotel to be stored: (5)
Hotel_ID – Integer
Hotel_Name – String
Location – String
No_of _Rooms – Integer
As a programmer of the company, you have been assigned to do this job for Shreya.
(a) Write a function to input the data for a record and add to a binary file.
(b) Write a function in Python which accepts Location as a parameter and counts and returns the number of
hotels by the given location stored in a binary file.
Ans. (a) import pickle
def datafile():
f=open("Hotel.dat","rb")
Hotel_ID=int(input("Enter hotel id"))
Hotel_Name=input("Enter name of the hotel")
Location=input("Enter location of the hotel")
No_of_Rooms=int(input("Enter number of rooms in a hotel"))
record=[Hotel_ID, Hotel_Name, Location, No_of_Rooms]
pickle.dump(record,f)
f.close()
(b) import pickle
def CountRecords(Location):
f=open("Hotel.dat","rb")
count=0
try:
while True:
record=pickle. load(f)
if Location == record[2]:
count=count+1
except:
f. close()
return count
37. Canvo International Inc. is planning to connect its Bengaluru Office Set-up with its Head Office in Delhi. The
Bengaluru Office of Canvo International Inc. is spread across an area of approximately 1 square kilometre,
consisting of 3 blocks: Human Resources, Administration and Academics. As a network expert, you have to
suggest solutions to the following five queries, i.e., (a) to (e), raised by them, keeping in mind the distances
between various blocks and the number of computers in each block. (5)
Bengaluru Office Set-up
Delhi
Head Human Resources
Office
Administration Academics
Shortest distances between various blocks:
Human Resources to Administration 100 m
Human Resources to Academics 65 m
Academics to Administration 110 m
Delhi Head Office to Bengaluru Office Set-up 2350 km
A.44 Computer Science with Python–XII