Control

Computers appear to be smart and powerful because they make billions of repetitive decisions every second. In this section, you will learn about decisions (selection) and repetition.

Readings from the book The Practice of Computing Using Python.

Chapter 2: Control

Videos

  1. Booleans and Logical Operations
  2. Booleans are data that have values True or False, and that makes them useful for making decisions.

    1. Booleans (Video)
    2. Boolean Logic (Video)
  3. Selection (Decisions)
  4.             if Boolean-expression-I:
                    suite-of-statements
                elif Boolean-expression-II:
                    suite-of-statements
                else:
                    suite-of-statements 
    1. Selection if (Video)
    2. Selection if with else (Video)
    3. Nested if (Video)
  5. Repetition using while
  6.              while Boolean-expression:
                    suite-of-statements 
    1. While (Video)
    2. While with else (Video)
    3.          while Boolean-expression-I:
                  suite-of-statements 
                  if Boolean-expression-II:
                      break      # Exit loop now; skip else 
                  if Boolean-expression-III:
                      continue   # Go to top of loop now 
                  suite-of-statements 
               else:
                  suite-of-statements # if we did not hit a break 
    4. Nested while (Video)
  7. Examples using if and while
    1. An example using if and while (Video)
    2. Solve this puzzle substituting unique, non-zero integers for each letter:

        HERE
       + SHE
       -----
       COMES 
    3. The classic fizzbuzz problem (Video).
    4. Write a program that prints the numbers from 1 to 100. However, for multiples of three print "Fizz" instead of the number, and for the multiples of five print "Buzz." For numbers that are multiples of both three and five print "FizzBuzz."

Assignments

  1. Chapter 2 Exercises on Codio
  2. Lab02 (do pre-lab first on D2L)