Name:______________________________     Alpha:________________________________ 
Print this page and give the answers.
  1. [5pts] Consider a file hello.py.
    # hello.py 
    def func():
        print("hello world IT430")
    
    def func2():
        print("Go Navy!")
    
    Fill out the blank on the right to ensure correctness.
    
    >>> import hello
    >>> hello.func()
    hello world IT430
    >>> hello.func2()
    Go Navy!
    
    
    >>> 
    >>> __________________________________________________
    >>> func()
    hello world IT430
    >>> func2()
    Go Navy!
    
  2. [40pts] Assuming the following definitions, fill in the table.
    
    a = b"hello world"
    b = "hello world"
    c = 0b1101 
    d = 0x73 
    
    Possible types are:
    str, int, bytes, float
    expressiontypevalue
    a[1]
    b[1]
    c | 0x10
    c & 0x10
    chr(d ^ 0x40)
    d >> 4
    c / 2
    c // 2
    c % 7
    (-c) % 7
  3. [10pts] What is the output of the following code, and why?
    def f(a, b, c):
      a = 3; b[0] = "t"; c['k'] = "hello"
    
    x = 1
    y = [1]
    z = {'k':0}
    f(x,y,z)
    print(x, y, z)
    
    Output:
    
    Why: 
    
    
    
    
    
    
    
  4. [15pts] What is the output of each of the following pieces of code? Explain.
    a = "hello"
    def f():
      print(a)
    
    f()
    
    a = "hello"
    def f():
      a = "jello"
      print(a)
    
    f()
    print(a)
    
    a = "hello"
    def f():
      global a
      a = "jello"
      print(a)
    
    f()
    print(a)
    
    
    
    
  5. [16pts] Fill out the blanks below.
    
    >>> A = [[]]*3
    >>> A
    
    __________________________
    
    >>> A[0].append(1)
    >>> A
    
    __________________________
    
    >>> B = [[] for i in range(3)]
    
    __________________________
    
    >>> B[0].append(1)
    >>> B
    
    __________________________
    

Submission deadline

Check the course calendar for the deadline. Bring your work to class.