Quiz 3 Solution

  1. Why do we use pseudo-code to document an algorithm, rather than a natural language like English or a programming language like Python?

    Pseudo-code is more precise than natural language, and yet easier for beginners to understand than a programming language.

  2. Carefully trace the following algorithm. What does it output? Be sure to mark a section of your answer as the output, separate from your scratch work.

    1. Let N be 8
    2. Set I to 1
    3. If I > N then stop.
    4. If I < 4 or I is odd, then output I
    5. Set I to I+1
    6. Go back to step 3.

    Tracing pseudo-code from Christopher League on Vimeo.

  3. Give an example of each kind of pseudo-code instruction. Refer to the relevant step numbers in the algorithm above.

    1. Input: Something like “Let N be a positive integer” (where the user can choose which integer).
    2. Output: A statement that says “output” or “print”, like step 4.
    3. Variable assignment: A statements that says “Set name to value”, like steps 2 or 5.
    4. Conditional: A statement using an “if”, like steps 3 or 4.
    5. Loop: A statement that repeats previous steps, like step 6 above.