To Lecture Notes

IT 211 -- Jan 9, 2019

Review Exercises

  1. What are the four ways to create a Python script and execute it?
    1. Run a script file called a module from the Idle IDLE.
    2. Enter and run Python statements interactively in an IDLE Shell Window
    3. Enter and run Python statements using interactive python. Enter py to start Interactive Python.
    4. Run the script test.py from a Command/Terminal Window like this:
      > py test.py
      
  2. What is the exponentiation operator?
    Ans: **
  3. Translate these formulas into Python:
    a =
    x + 2y

    x - 3y
                     b = 1 + 3x-5n
    Ans: a = (x + 2 * y) / (x - 3 * y)
         b = 1 + 3 * x ** (3 * n)
    

    Create a Python script that computes a and b for the values x = 3, y = 5, and n = 2. In the output, round the value of a to four digits after the decimal; round the value of b to six digits after the decimal. Ans: Here are the script and output:
    x = 3
    y = 5
    n = 2
    a = (x + 2 * y) / (x - 3 * y)
    b = 1 + 3 * x ** (-5 * n)
    print("Output:", round(a, 4), round(b, 6))
    
    # Output:
    Output: -1.0833 1.000051
    
  4. Download and run the script from the FrenchFlag Example and display it in a computer lab using Adobe PhotoShop.
    For your Windows computer, you can download IrfanView
    For your Mac computer, you can download Toy Viewer for free. It requires operating system 10.8+.
     
  5. What does this PPM image look like?
    PPM means Portable Pixel Map, represented by the magic number P3.
    P3 5 5 255
    128 128 128  128 128 128  128 128 128  128 128 128  128 128 128
    128 128 128  255 128   0  255 128   0  255 128   0  128 128 128
    128 128 128  255 128   0    0 128 128  255 128   0  128 128 128
    128 128 128  255 128   0  255 128   0  255 128   0  128 128 128
    128 128 128  128 128 128  128 128 128  128 128 128  128 128 128
    
    The header line P3 5 5 255 indicates the following:
    P3:  Portable Pixel Map (ppm)
    5:   Image is 5 pixels wide
    5:   Image is 5 pixels high
    255: Component value range is 0 to 255.
    
    Pixels contain red, green, and blue components.
    Ans: 128 128 128 represents the color median dark gray; 0 255 128 represents orange because it is between red = 255 0 0 and yellow = 255 128 0; 0 128 128 is dark bluegreen, which is teal. Here is the image: tiny.ppm.

DOS/Unix Commands

Constants, Datatypes, and Variables

Operators

Variable Trace Tables

Input Validation

Project 1