Helper Functions
def generate_ID (collection, offset):
"""
param: collection (dict) - a collection of items that works with max()
param: offset (int) - an integer offset that's added to the first ID.
If the collection is empty, then the first ID is the offset value.
Otherwise, the function retrieves the max value from the collection,
and returns its value+1.
returns:
The computed ID, based on the offset or the max element in the collection.
If max value is not an integer, the function returns an error string:
"Error, non-integer IDs"
For example, calling the function with
{} and 0 as the offset should return 0, since the collection is empty
and 0 is the offset;
{} and 1000 as the offset should return 1000.
{500: (16.5, None)} and 1000 as the offset should return 501, since the
collection is not empty and 500 (the dict key) is the max value.
"""
def add_order (all_orders, price, user_dict, offset):
"""
The function expects
param: all_orders (dict) - a dictionary that contains ticket orders
param: price (float) - a float that's >=0
param: user_dict (dict) - stores the integer "age" and the status of
the discount options
param: offset (int) - an integer that's needed by the generate_ID()
The function stores the offset as the key that maps to the tuple containing
two elements: the price and the user_dict. The function should not modify
the all_orders dictionary.
Helper function:
generate_ID() to store the order ID
returns: either an error from the generate_ID() or a NEW dictionary with
the created order.
"""