Hotels (2 points)

A travel agency saves the available hotels in a file. Each line contains the following data for a hotel, separated by a colon (:): the name (str), the price for a night (int), the number of stars (int) and a variable number of names (str) corresponding to the hotel facilities.

Write function hotels() that takes the name of a file as such described (str), the name of a second file (str), an amount in euros (int) and a list of required facilities (str). This function analyses the hotels given in the first file and writes in the second file those hotels that meet the following conditions:

  • the hotel night price is less than or equal to the given amount and

  • there is at least one of the required facilities in the hotel.

In this second file, the hotels are in the same order as in the first given file. Lines of this second file have the following data, also separated by a colon: the name, a string with as much asterisks (*) as the number of stars of the hotel, the price per night and the number of required facilities offered by the hotel.

Save this function in file hotels.py.

Example:

For a data file with the name 'hotcan1.txt' with the following content:

Marriot:95:3:parking:children menu:wifi:TV:outdoor pool:bycicle
Hilton:180:5:parking:laundry:children menu:wifi:TV:outdoor pool:spa:golf:bycicle:trekking
Barceló:89:3:parking:children menu:wifi
Scandic:75:2:amenities:wifi:TV
Atlas:98:4:parking:laundry:children menu:wifi:TV:ootdoor pool:golf:bycicle:trekking:amenities

and executing the following statements:

>>> lfac = ['parking', 'children menu', 'outdoor pool', 'bycicle']
>>> hotels('hotcan1.txt', 'hotfin1.txt', 100, lfac)

an output file with name 'hotfin1.txt' will be created with the following content:

Marriot:***:95:4
Barceló:***:89:2
Atlas:****:98:3

Note

Tests for automatic debugging are provided in file test-hotels.txt.