Theatre (3 points)¶
A theatre has gathered data concerning the occupancy (number of sold
tickets) of its hall for several plays and several sessions for each
play. These data are represented with a nested list: in
each sublist of it there is the name of a play (str) and
the occupancy (int) for several sessions in which this
play has been performed. For example, the sublist ['Mary Poppins',
414, 232, 119] shows that the play with name 'Mary Poppins' has
been performed in three sessions with an occupancy of 414, 232 and 119
respectively.
We define the occupancy average of a play as the occupancy average
of its sessions and the occupancy rate of a play as the percentage
of the occupancy average with respect to the hall capacity. For the
previous sublist example and a hall capacity of 478, the occupancy
average can be computed as (414 + 232 + 119)/3 which is
255.0, and the occupancy rate can be computed as
255.0/478*100 which is 53.34%.
Write function theatre() that takes a nested list
as that described in the first paragraph, the capacity of the theatre
hall (int) and a percentage (float). This
function returns a list with the play names
(str) of those plays with an occupancy rate
less than the given percentage. The ordering of the play names in the
output list must be the same as in the input list.
For the previous example and a given percentage of 60% the name of
the play 'Mary Poppins' would be included in the output list.
Save this function in file theatre.py.
Examples:
>>> lplays1 = [['Mary Poppins', 414, 232, 119],
... ['Les Miserables', 401, 402, 481, 422, 455, 398],
... ['The Great Gatsby', 212, 132, 167, 176],
... ['Good', 98, 145, 198, 101],
... ['Frozen', 356, 342, 289, 456, 432, 388],
... ['Skyfall', 209, 231, 235, 198, 223]]
>>> theatre(lplays1, 478, 60)
['Mary Poppins', 'The Great Gatsby', 'Good', 'Skyfall']
>>> theatre(lplays1, 478, 80)
['Mary Poppins', 'The Great Gatsby', 'Good', 'Frozen', 'Skyfall']
>>> theatre(lplays1, 478, 40)
['The Great Gatsby', 'Good']
Note
More tests are provided in file test-theatre.txt.