'''Examples of list functions.
Exercises:
- Make sure you understand why broken_v1 and broken_v2 don't work.
- Expand the testing to a thorough and convincing set of test cases.
- write and test functions total_length and get_valid_response 
  (a fancier version of one we discussed under the topic of while loops).
'''

def square_list(int_list):
    '''Return a new list that contains the squares of
    the numbers from int_list (a list of ints).'''

    # Compare how we'd write the function if we made
    # a list of the right length to start, and then
    # changed what was in it.
    # squares = int_list[:]
    squares = []
    for number in int_list:
        # append the square of number to the end of 
        # list squares.
        squares.append(number ** 2)
    return squares

def broken_v1(original_list):
    '''Convert all strs in the original_list (a list of
    strs) to uppercase.'''

    # This doesn't work.
    for s in original_list:
        s.upper()
    # And a return won't save you!
    
def broken_v2(original_list):
    '''Convert all strs in the original_list (a list of
    strs) to uppercase.'''

    # This doesn't work either.
    for s in original_list:
        s = s.upper()
    # And a return won't save you!
    
def to_upper(original_list):
    '''Convert all strs in the original_list (a list of
    strs) to uppercase.'''
        
    for index in range(len(original_list)):
        original_list[index] = original_list[index].upper()        
        
    # Don't return anything.  That would be going "outside"
    # the contract.
    
def total_length(L):
    '''L is a list of strs.  Return the total length of all the strs in L.'''
    
    pass
    
def get_valid_response(p, valid_list):
    '''Use string p to prompt for and return a string that is 
    from valid_list (a list of strings).'''
    
    pass


if __name__ == "__main__":
    
    # Exercise: expand this to a thorough (convincing)
    # set of tests.
    L = [5, 2, -3, 245]
    assert square_list(L) == \
           [25, 4, 9, 60025], \
           "square_list gave the wrong result"
    assert L == [5, 2, -3, 245], \
           "square_list changed the given list!"    
   
    # For this function, we don't assert that
    # to_upper(L) == anything.
    # We separately make an assertion about 
    # L afterwards.  Why?
    L = ["abc", "DeF", "ghij"]
    answer = to_upper(L)
    assert L == ["ABC", "DEF", "GHIJ"]
    assert answer == None