Ejemplo n.º 1
0
def get_longest_name_id(table):  # table
    """
        Question: What is the id of the customer with the longest name?

        Args:
            table (list): data table to work on

        Returns:
            string: id of the longest name (if there are more than one, return
                the last by alphabetical order of the names)
        """

    # your code
    longest = 0
    name_list = []
    for i in range(len(table)):
        if len(table[i][1]) > longest:
            longest = len(table[i][1])
    reli = []
    for i in range(len(table)):
        if len(table[i][1]) == longest:
            reli.append(table[i][0])
            name_list.append(table[i][1])
    sorting(name_list)
    name_list = name_list[::-1]
    longest_name = name_list[0]
    for i in range(len(table)):
        if table[i][1] == longest_name:
            return table[i][0]
def get_lowest_price_item_id(table):
    pass
    """
    Question: What is the id of the item that was sold for the lowest price?
    if there are more than one item at the lowest price, return the last item by alphabetical order of the title

    Args:
        table (list): data table to work on

    Returns:
         string: id
    """

    # your code
    list_of_min = []
    list_of_prices = []
    for list in table:
        list_of_prices.append(list[2])
    min_price = min(list_of_prices)
    for list in table:
        if list[2] == min_price:
            list_of_min.append(list[0])
    sorting((list_of_min))
    for i in range(len(list_of_min)):
        if i == len(list_of_min) - 1:
            result = list_of_min[i]
    return result
Ejemplo n.º 3
0
def get_persons_closest_to_average(table):
    """
    Question: Who is the closest to the average age?

    Args:
        table (list): data table to work on

    Returns:
        list: list of strings (name or names if there are two more with the same value)
    """

    # your code
    lnu = []
    for i in range(len(table)):
        lnu.append(str(2019 - int(table[i][-1])) + table[i][1])
    nu = []
    nusum = 0
    for i in range(len(lnu)):
        nu.append(lnu[i][0] + lnu[i][1])
        nusum += int(nu[i])
    navg = nusum / len(lnu)
    avg = int(navg * -1 // 1)
    avg = avg * -1
    reli = []
    nums = []
    name = []
    numsort = []
    for i in range(len(nu)):
        nums.append(abs(int(nu[i]) - 46))
        numsort.append(abs(int(nu[i]) - 46))
        s = ""
        for j in range(2, len(lnu[i])):
            s += lnu[i][j]
        name.append(s)

    result_list = []
    sorting(numsort)
    for i in range(len(nums)):
        if nums[i] == numsort[0]:
            result_list.append(name[i])

    return result_list
Ejemplo n.º 4
0
def get_oldest_person(table):
    """
    Question: Who is the oldest person?

    Args:
        table (list): data table to work on

    Returns:
        list: A list of strings (name or names if there are two more with the same value)
    """

    # your code

    lnu = []
    for i in range(len(table)):
        lnu.append(str(2019 - int(table[i][-1])) + table[i][1])
    nu = []
    for i in range(len(lnu)):
        nu.append(lnu[i][0] + lnu[i][1])
    sorting(nu)
    nu = nu[::-1]
    hm = 0
    for i in range(len(nu)):
        if nu[0] == nu[i]:
            hm += 1
    reli = []
    ma = nu[0]
    for i in range(len(lnu)):
        s = lnu[i][0] + lnu[i][1]
        l = ""
        if s == ma:
            for j in range(len(lnu[i])):
                if j > 1:
                    l += lnu[i][j]
        if len(l) > 0:
            reli.append(l)
    return reli