• Practice
  • 15 practice questions

Final self-assessment: programming concepts practice

Test yourself on the whole course: 15 questions with answers explained.

If something looks wrong, please tell us.

Attempt all 15 questions, then check your answers. These are a little harder than the checks after each lesson. Which lessons cover which questions: questions 1-3: lesson 1, "Algorithms and flowcharts"; questions 4-6: lesson 2, "Variables, data types and operators"; questions 7-9: lesson 3, "Control structures: decisions and loops"; questions 10-12: lesson 4, "Types of errors, languages and paradigms"; questions 13-15: lesson 5, "Programming concepts mixed practice".

Final self-assessment

  1. 1. Trace: S = 0; N = 2; while N <= 8, add N to S and then add 2 to N; print S. What is printed?

    1. 12
    2. 30
    3. 20
    4. 8
    Show answer

    Answer: C. N takes 2, 4, 6, 8, so S becomes 2, 6, 12, 20. Then N = 10 fails the test and 20 is printed.

  2. 2. A flowchart reads A and B, decides whether A > B and prints the larger. Which symbols does it use for these three steps, in order?

    1. Rectangle, oval, diamond
    2. Parallelogram, diamond, parallelogram
    3. Diamond, parallelogram, rectangle
    4. Oval, rectangle, diamond
    Show answer

    Answer: B. Reading is input (parallelogram), the test is a decision (diamond) and printing is output (parallelogram).

  3. 3. An algorithm repeats a step forever and never stops. Which requirement does it break?

    1. It must have input
    2. It must use a diamond symbol
    3. It must be finite (it must end)
    4. It must be written in a programming language
    Show answer

    Answer: C. An algorithm must be finite: it has to end after a limited number of steps.

  4. 4. Let A = 9 and B = 3. What is A - B * 2 + A / B?

    1. 6
    2. 15
    3. 0
    4. 7
    Show answer

    Answer: A. Multiply and divide first: 3 x 2 = 6 and 9 / 3 = 3. Then left to right: 9 - 6 + 3 = 6.

  5. 5. Using integer division, what are 47 / 6 and 47 % 6?

    1. 7 and 5
    2. 5 and 7
    3. 7 and 6
    4. 8 and 1
    Show answer

    Answer: A. 6 x 7 = 42 and 47 - 42 = 5, so the quotient is 7 and the remainder is 5.

  6. 6. Which line compares a value rather than storing one?

    1. X = 10
    2. IF X == 10
    3. X = X + 10
    4. Total = X
    Show answer

    Answer: B. == compares and gives true or false. = stores a value, so the other three lines are assignments.

  7. 7. Trace: K = 10; while K > 1, K = K - 3; print K. What is printed?

    1. 1
    2. -2
    3. 4
    4. 0
    Show answer

    Answer: A. K goes 7, 4, 1. When K is 1, the condition 1 > 1 is false, so the loop stops and 1 is printed.

  8. 8. Trace: S = 0; for I from 1 to 10 step 3, S = S + I; print S. What is printed?

    1. 12
    2. 22
    3. 55
    4. 18
    Show answer

    Answer: B. I takes 1, 4, 7, 10, so S becomes 1, 5, 12, 22. Output: 22.

  9. 9. Which of these loops is an infinite loop?

    1. X = 1; while X != 10, X = X + 2
    2. X = 5; while X > 0, X = X - 1
    3. X = 1; while X < 5, X = X + 1
    4. X = 10; while X < 5, X = X + 1
    Show answer

    Answer: A. X takes 1, 3, 5, 7, 9, 11 ... and is always odd, so it never equals 10 and the condition never becomes false. The other loops stop (or never start).

  10. 10. Which kind of error gives no error message and is found only by testing?

    1. Syntax error
    2. Runtime error
    3. Logical error
    4. Compile error
    Show answer

    Answer: C. A logical error lets the program run and give a wrong result, so nothing reports it; testing finds it.

  11. 11. Which pairing is correct?

    1. Runtime error: happens during execution, such as dividing by zero
    2. Syntax error: the program runs but gives a wrong answer
    3. Logical error: found by the translator before running
    4. Runtime error: a missing bracket stops compilation
    Show answer

    Answer: A. Runtime errors happen while running. A wrong answer is a logical error, and a missing bracket is a syntax error found before running.

  12. 12. Which set lists key ideas of object-oriented programming?

    1. Sequence, selection, iteration
    2. Syntax, runtime, logical
    3. Class, object, inheritance, encapsulation, polymorphism
    4. Oval, diamond, rectangle, parallelogram
    Show answer

    Answer: C. OOP is built on class, object, inheritance, encapsulation and polymorphism. The other sets are control structures, error kinds and flowchart symbols.

  13. 13. Trace: N = 3; while N < 50, N = N x 3; print N. What is printed?

    1. 27
    2. 243
    3. 50
    4. 81
    Show answer

    Answer: D. N goes 9, 27, 81. At 27 the condition 27 < 50 is true, so it becomes 81; then 81 < 50 fails. Output: 81.

  14. 14. A loop runs for I from 1 to 20 and prints I only when I % 4 == 0. How many numbers are printed?

    1. 5
    2. 4
    3. 6
    4. 20
    Show answer

    Answer: A. The multiples of 4 up to 20 are 4, 8, 12, 16 and 20, which is 5 numbers.

  15. 15. How many times does the body of a loop run for I from 3 to 15 step 3?

    1. 4
    2. 13
    3. 5
    4. 15
    Show answer

    Answer: C. I takes 3, 6, 9, 12 and 15, which is 5 values. (15 - 3) / 3 + 1 = 5; forgetting the + 1 gives the trap answer 4.

Revisit the lesson for any question you missed: questions 1-3: lesson 1, "Algorithms and flowcharts"; questions 4-6: lesson 2, "Variables, data types and operators"; questions 7-9: lesson 3, "Control structures: decisions and loops"; questions 10-12: lesson 4, "Types of errors, languages and paradigms"; questions 13-15: lesson 5, "Programming concepts mixed practice".

Privacy · Terms · Refunds · Delivery