Python Homework #12

Instructions:

Remember: You'll be writing two functions. Both of these functions will take a list of integers, and add 1 to every element, e.g. [10, 20, 30] becomes [11, 21, 31].
  1. Write a function add1Copy(L). L is a list of integers. This function should return a copy of L, with each element increased by 1. This function should not modify L.

  2. Write a function add1Modify(L). L is a list of integers. This function should modify each element of L (using L[i] =) to increase each by 1. This function should return L.
    
    

  3. Use the following test cases to test your two functions:
    A = [10,20,30]
    B = add1Copy(A) # B should be [11,21,31]
    
    C = [20,30,40]
    D = add1Modify(C) # D should be [21,31,41]
    
    print("Copied A, B: ", A, B)
    print("Modified C, D: ", C, D)
    
  4. Make sure that A is not incremented, since add1Copy() shouldn't modify it.
  5. Make sure that C is incremented, since C and D should be the same list (doesn't create a copy)