Session 6 Preparation — Videos, Reading and Quizzes

Quizzes:

Do this Quiz on Session 6 as you watch the videos and do the reading (as listed below). This document is a Microsoft Word document; here is the same Quiz on Session 6 (pdf) as a PDF.

You can either:

In either case, turn it in via the Session 6 Dropbox on our Moodle site.

Videos and Reading (online and textbook):

All of the following are required except the items labeled Optional are, well, optional (i.e., things that may be interesting but do not directly pertain to your success in this course).

  1. Conditionals (IF statements and variants thereof) and Relational Operators
    1. Optional online reading: Section 4.1. (if statements) from the Python Tutorials at python.org.
      • This is a nice summary for those who already know about IF statements in other languages but need to see how to write them in Python.
    2. Textbook reading: Section 3.1 — The IF Statement (pages 91 - 96, 6 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • What IF statements are, and why we need them.
        • The notation for IF statements (nicely summarized in Syntax 3.1 on page 94).
        • The idea and notation of compound statements and a statement block, as seen in the example on the top of page 95.
        • What belongs inside an IF statement, and what does not. See Programming Tip 3.1 on page 96.
    3. Optional textbook reading Special Topic 3.1 — Conditional Expressions
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Python is designed for engineers to be productive. As such, it has considerable syntactic sugar — notation for doing something in a shorter or more elegant way than more standard notation would allow. This section shows an example of syntactic sugar called conditional expressions, for the adventurous among you. Your text does not use conditional expressions, nor (probably) will we.
    4. Textbook reading: Section 3.2 — Relational Operators (pages 97 - 101, 5 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • The six relational operators in Table 1 on the top of page 98.
        • How to use relational operators per Table 2 on the top of page 99 (pay special attention to the three common errors that it shows).
        • The fact that you should not compare two floating point numbers to see if they are equal, but rather to see if they are close enough. See Common Error 3.2 — a critical section for any engineer!
        • What it means for two strings to be equal.
    5. Optional textbook reading: Special Topic 3.2 — Lexicographic Ordering of Strings
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Refer back to this section if you ever need to know the ordering of strings, e.g. whether Daphne is less than or greater than daphne.
    6. Optional textbook reading: How To 3.1 — Implementing an IF Statement and Worked Example 3.1 — Extracting the Middle
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • These are two longer examples if you feel you need them.
  2. The Accumulator Pattern (revisited)
    • Video (embedded in a web page) [9:36 minutes]
    • Video (as an mp4 that you can download if you want)
  3. More on Conditionals (IF statements and variants thereof)

    Recall that you should have already done some reading on conditionals (see above).

    1. Textbook reading: Section 3.3 — Nested Branches (pages 106 - 109, 4 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • The concept of levels of decision making, as exemplified in Table 3 on page 106.
        • The notation for nested IF statements, per the example on page 107.
        • The useful Programming Tip 3.2 on hand-tracing.
    2. Textbook reading: Section 3.4 — Multiple Alternatives (pages 109 - 112, 4 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • The concept of multiple alternatives, as demonstrated in Table 4.
        • The notation for if-elif ... else statements, and why that notation is better than nested IF statements for describing multiple alternatives.
        • The importance of the order in which the conditions are listed in if-elif ... else statements, and how to get that order right.
    3. Optional textbook reading: Section 3.5 — Flowcharts (pages 112 - 115, 3 pages)
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Optional reading, but be sure you can READ a flowchart (and know what one is). Some would say that flowcharts are rarely of use in problems of real-world size, but it is important that you know what they are.
  4. Test Cases — Coverage and Boundary Testing
    1. Textbook reading: Section 3.6 — Problem Solving: Test Cases (pages 116 - 117, 2 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Read this important section carefully. Be sure you understand:
        • What it means to cover all the branches of the program.
        • What a boundary condition is, and why they are important to test.
        • What testing for invalid input means, and when you should and should not include such testing.
        • What Test-First Programming is and its two primary benefits:
          • It clarifies the specification (WHAT your code needs to do).
          • It gives insight into finding a reasonable implementation (HOW your code does it).
      • AFTER doing the entire quiz, THEN read this answer to a quiz question on testing.
  5. Optional (but highly recommended for skimming) online reading: Test-First Programming