Cafeteria

The context is a cafeteria shop. Consider the orders including a number of drinks consumed, 'cafe' for example, and foods consumed, 'donut' for example. We need to calculate the price to pay for a given order, with two total figures: the total of drinks and the total of foods.

An order is represented as a text (str) ended by a dot '.' with exactly 4 items separated by coma and space ', ', although every item can be anything: a drink, a food or something unknown. Each item comes with three informations separated by space (' '):

  • the number of units (positive integer)

  • the name of a product

  • the unit price (a float number)

For instance, '2 cafe_llet 1.80, 3 tallat 1.50, 2 donut 1.55, 2 T-shirt 15.0.'.

To identify whether a product name is a drink or a food, two strings with all drink and food names respectively, separated by space (' ') are available. For example,


>>> drinks = 'cafe tallat cafe_llet te infu aigua'
>>> foods = 'cruasant muffin napolitana donut mini'

Names that do not correspond to any drink or food in this listings should just be disregarded.

We wish to get a text indicating the total for drinks and the total for foods to be paid. The format of this text must be 'The drinks total is XX€ and the foods total is YY€.' where XX and YY are strings representing float numbers with those totals respectively.

In the above exemple, the total of drinks is 8.10 coming from adding the value of 2 'cafe_llet' s and 3 'tallat' s. The total of foods is 3.10 for the 2 'donut'. The 'T-shirt' item is disregarded since it is not a food or a drink.


You are required to deliver the following functions (they have the same grade weight) in the module cafeta_module (file cafeta_module.py):

Firstly, an auxiliar function specified as follows:

cafeta_total_update(total_drink, total_food, item, drinks, foods)

such that

given

  • total_drink, total_food, two float indicating the totals for drinks and foods respectively processed so far

  • item, a str with an item from an order in the format described above

  • drinks, a str with all drink names separated by space (' ')

  • foods, a str with all foods names separated by space (' ')

returns two float with the totals for drinks and foods properly updated by adding the values for the product and amount in item according to whether it is a drink or a food (hence, one of the totals will remain the same)

For example:


>>> drinks = 'cafe tallat cafe_llet te infu aigua'
>>> foods = 'cruasant muffin napolitana donut'

>>> td, tf = cafeta_total_update(0.0, 0.0, '2 cafe_llet 1.80', drinks, foods)
>>> round(td, 2), round(tf, 2)
(3.6, 0.0)

>>> td, tf = cafeta_total_update(8.1, 0.0, '3 cruasant 1.05', drinks, foods)
>>> round(td, 2), round(tf, 2)
(8.1, 3.15)

Doctests are available in the cafeta_total_update.test file.


Secondly, the main function:

cafeta_total_calc(order, drinks, foods)

such that

given

  • order a str with the order format described above.

  • drinks, a str with all drink names separated by space (' ')

  • foods, a str with all foods names separated by space (' ')

returns a str indicating the totals for drinks and foods corresponding to this order in the format described above. Both totals must be rounded to 2 decimals.

For instance,


--lists-ini

>>> drinks = 'cafe tallat cafe_llet te infu aigua'
>>> foods = 'cruasant muffin napolitana donut mini'

--lists-fi

>>> s = '2 cafe_llet 1.80, 3 tallat 1.50, 2 donut 1.55, 3 cruasant 1.05.'
>>> cafeta_total_calc(s, drinks, foods)
'The drinks total is 8.1€ and the foods total is 6.25€.'

>>> s = '2 machiato 1.20, 2 cruasant 1.3, 3 donut 1.5, 1 mini 2.5.'
>>> cafeta_total_calc(s, drinks, foods)
'The drinks total is 0.0€ and the foods total is 9.6€.'

Doctests are available in the cafeta_total_calc.test file.

Warning

This function must be implemented by calling the previous function.