Test 1

Date & Time

Wednesday, February 21, 12:30pm-1:45pm, PM 110

Overview

Test 1 will cover all material from the beginning of the semester through lazy evaluation. This material includes everything discussed in lectures and covered in assignments, and aligns with chapters 1-6 from the recommended text. We have covered some additional topics the text has not, and we did not cover the data science additions to each chapter. Because this is a programming principles course, there will be questions related to principles as well as questions that involve syntax. You may be asked to write, analyze, and/or debug code.

Format

  • Multiple Choice
  • Free Response

Example Types of Free-Response Questions

  • Given a block of code, locate all errors and detail how you would fix them. For example,
    int[3] output;
    float[] arr = [1.2, 3.4, 5.6];
    for(int i = 0; i < arr.length; i++) {
        output.add(arr[i] ^ 2); // squares value
    }
  • What advantages does an interpreted language like Python have over a compiled language like C++?
  • What is the principle of “Don’t Repeat Yourself”? How does it make code more manageable?
  • What are the conventions for identifiers in Python?
  • Discuss the controversy surrounding the goto statement, including Dijkstra’s famous letter.
  • Compare the loop-and-a-half, infinite-loop-break, and assignment-expression approaches for while loops. Which is best?
  • What are the similarities and differences between sequences and collections? Which python constructs fall into each category?
  • What types of delimiters can be used to define a literal string value?
  • Given a function f that takes the parameters a, b, and c, but not necessarily in that order, and returns a + b - c, if f(5,0,100) returns 95, what is the first argument (letter)?
  • What is the difference between mylist.sort() and sorted(mylist)?
  • Given a block of code, rewrite it to be more concise (or efficient). For example,
    d = [2,3,5,7]
    output = []
    for i in d:
        output.append(i ** 2)
  • What makes a list comprehension different from a generator?
  • When is lazy evaluation more efficient than strict evaluation?
  • What strategy does python use when evaluating an expression like i >= 0 and j < 10? Why does this involve lazy evaluation?