Offices (2 points)¶
A company is conducting a study of the occupancy of its offices. The
corresponding data is stored in a nested list. Each sublist
of it corresponds to a floor of the company building and consists of a
first item with the name of the floor (str) and a variable
number of tuples (tuple) corresponding to the offices in this
floor. Each tuple has 3 items: the office name (str), the
number of seats in this office (int) and the number of
occupied seats (int). Besides a name, each floor has a number
which is the index (position) of the floor in the nested list.
Write function offices() that takes a list as that described
and creates a number of files equal to the number of floors in the
company building. The name of these files begins with 'floor',
then it goes the floor name and the floor number and ends with the
extension '.txt'. These files have a line for each office in the
corresponding floor that has free seats, with the name (str)
and free seats (int) of this office, separated by a colon
(':').
Save this function in file offices.py.
Example:
The following statements:
>>> lo1 =[['A', ('A.1', 4, 3), ('A.2', 4, 2), ('A.3', 6, 2)],
... ['B', ('B.1', 3, 1), ('B.2', 2, 2), ('B.3', 6, 4), ('B.4', 3, 2)]]
>>> offices(lo1)
define a company building with two floors with names 'A' and
'B' and numbers 0 and 1, respectively, and will create two
files with names 'floorA0.txt' and 'floorB1.txt'.
The contents of file 'floorA0.txt' will be:
A.1:1
A.2:2
A.3:4
and the contents of file 'floorB1.txt' will be:
B.1:2
B.3:2
B.4:1
Note
Tests for automatic debugging are provided in file test-offices.txt.