""" There are three parts to Prac 4:

1. See discount_test.py for instructions on Part 1. Please complete Part 1,
   Tasks 0-3 before moving on to Parts 2 and 3.

2. Implement length_order in this file. A test program is provided in
   length_order_test.py.
   
3. Implement some_pears in this file. A test program is provided in
   some_pears_test.py
   
When done, submit the following files:
 - discount_test.py
 - discount.py
 - prac4.py
"""

def length_order(s1, s2): # Part 2
    """ Return a 2-tuple containing strings s1 and s2, ordered by length, i.e.,
    return (a, b) such that a is the shorter of s1 and 2, and b is the longer.
    If both strings have the same length, return them in lexicographic 
    (i.e., dictionary) order.
    Examples:
        length_order("a", "aa") => ("a", "aa")
        length_order("abc", "de") => ("de", "abc")
        length_order("tortoise", "hare") => ("hare", "tortoise")
        length_order("empty", "") => ("", "empty")
        length_order("abc", "def") => ("abc", "def")
        length_order("cat", "bag") => ("bag", "cat") 
    """
    
    if len(s1) < len(s2):
        return s1, s2
    elif len(s1) > len(s2):
        return s2, s1        
    
    # lengths are equal
    if s1 <= s2:
        return s1, s2
    else:
        return s2, s1


def some_pears(numbers): # Part 3
    """ Given a list of n numbers, return a list of n+1 numbers, where:
    - the first and last elements are the first and last of the input list
    - for the rest, ith value is the sum of the ith and i-1th input
    Precondition: numbers is a nonempty list of numbers
    Examples:
       input:   [2, 6]
       output: [2, 8, 6]
       
       
                0  1  2
       input:  [2, 3, 4]
       output: [2, 5, 7, 4] """
    
    middles = []
    for i in range(len(numbers)-1):
        middles.append(numbers[i] + numbers[i+1])
    
    return [numbers[0]] + middles + [numbers[-1]]
    
