Holidays (3 points)¶
A travel agency saves the booked trips in a file. There is a header
line with the name of the travel and then a line for each
customer. Each of these lines has the following data separated by a
hyphen (-): the customer name (str), the room type
(str) that can be 'double' or 'single', the number of
hotel nights (int) and a variable number of names
(str) for extra excursions booked by this customer. There is
also a dictionary (dict) for extra excursions in which the
key is the name of the excursion (str) and the value is its
price (int).
Write function holidays() that takes the name of an input
file (str) and a dictionary of extra excursions prices as
those described, it also takes the hotel price for a night
(int) and a name of an output file (str). This
function must create an (output) file with the given name that will
have a line for each customer with the name of the customer
(str), a colon and a space (': ') and the total amount
that this customer must pay (int) followed by the euro symbol
('€'). The total amount for a customer includes the price for the
hotel nights and the extra excursions booked by them and it must be
the integer part of the computed result. The cost of a single room is
a 20% more expensive than the double one.
Save this function in file holidays.py.
Example:
For a data file with the name 'greece.txt' with the following content:
Greece
J. Smith-double-9-Santorini-Mykonos-Rhodes
A. Jones-single-8-Athens-Mykonos-Rhodes-Mycenae
B. Garcia-double-12-Santorini-Athens-Mykonos-Rhodes-Ephesus-Mycenae
J. Clark-single-9-Athens-Rhodes-Ephesus-Mycenae-Thessaloniki
and executing the following statements:
>>> dextra_gr = {'Santorini': 90, 'Athens': 100, 'Mykonos': 85, 'Mycenae': 110,
... 'Rhodes': 120, 'Ephesus': 115, 'Thessaloniki': 75}
>>> holidays('greece.txt', dextra_gr, 106, 'gr_bills.txt')
an output file with name 'gr_bills.txt' will be created with the
following content:
J. Smith: 1249€
A. Jones: 1432€
B. Garcia: 1892€
J. Clark: 1664€
Note
Tests for automatic debugging are provided in file test-holidays.txt.