Chapter 2

Contents: True/False | Multiple Choice | Discussion | Programs

True/False

  1. False
  2. True
  3. False
  4. True
  5. False
  6. True
  7. True
  8. False
  9. True
  10. False

Multiple Choice

  1. c
  2. a
  3. d
  4. c
  5. b
  6. b
  7. b
  8. d
  9. a
  10. d

Discussion

  1. Actual answers will vary, but should have some description of each step. The six steps are: Problem Analysis, Specification, Design, Implementation, Testing/Debugging, and Maintenance.
  2. The problem does not ask students to distinguish between programmer chosen names and keywords, so there may be some variation in approach. In this solution, "Regular" identifiers are in red, keyword identifiers in green, and expressions are underlined.
    # File: chaos.py                                         (comment)
    # A simple program illustrating chaotic behavior. (comment)

    def main(): #(function definition)
    print "This program illustrates a chaotic function" #(output)
    x = input("Enter a number between 0 and 1: ") #(input)
    for i in range(10): #(for loop)
    x = 3.9 * x * (1 - x) #(assignment)
    print x #(output)

    main()
  3. A Python for loop implements a definite loop. A counted loop is a specific kind of definite loop that is designed to iterate as certain number of times.
  4. These can be checked interactively.
    1. 0
      1
      4
      9
      16
    2. 3 1 4 1 5
    3. Hello
      Hello
      Hello
      Hello
    4. 0 1
      1 2
      2 4
      3 8
      4 16
  5. It's eaiser to create an algorithm without worrying about all the syntactic details of a language.

Programming Exercises

Code for Chapter 2 Exercises