- 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. Trace: S = 0; N = 2; while N <= 8, add N to S and then add 2 to N; print S. What is printed?
- 12
- 30
- 20
- 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. 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?
- Rectangle, oval, diamond
- Parallelogram, diamond, parallelogram
- Diamond, parallelogram, rectangle
- Oval, rectangle, diamond
Show answer
Answer: B. Reading is input (parallelogram), the test is a decision (diamond) and printing is output (parallelogram).
-
3. An algorithm repeats a step forever and never stops. Which requirement does it break?
- It must have input
- It must use a diamond symbol
- It must be finite (it must end)
- 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. Let A = 9 and B = 3. What is A - B * 2 + A / B?
- 6
- 15
- 0
- 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. Using integer division, what are 47 / 6 and 47 % 6?
- 7 and 5
- 5 and 7
- 7 and 6
- 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. Which line compares a value rather than storing one?
- X = 10
- IF X == 10
- X = X + 10
- Total = X
Show answer
Answer: B. == compares and gives true or false. = stores a value, so the other three lines are assignments.
-
7. Trace: K = 10; while K > 1, K = K - 3; print K. What is printed?
- 1
- -2
- 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. Trace: S = 0; for I from 1 to 10 step 3, S = S + I; print S. What is printed?
- 12
- 22
- 55
- 18
Show answer
Answer: B. I takes 1, 4, 7, 10, so S becomes 1, 5, 12, 22. Output: 22.
-
9. Which of these loops is an infinite loop?
- X = 1; while X != 10, X = X + 2
- X = 5; while X > 0, X = X - 1
- X = 1; while X < 5, X = X + 1
- 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. Which kind of error gives no error message and is found only by testing?
- Syntax error
- Runtime error
- Logical error
- 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. Which pairing is correct?
- Runtime error: happens during execution, such as dividing by zero
- Syntax error: the program runs but gives a wrong answer
- Logical error: found by the translator before running
- 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. Which set lists key ideas of object-oriented programming?
- Sequence, selection, iteration
- Syntax, runtime, logical
- Class, object, inheritance, encapsulation, polymorphism
- 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. Trace: N = 3; while N < 50, N = N x 3; print N. What is printed?
- 27
- 243
- 50
- 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. A loop runs for I from 1 to 20 and prints I only when I % 4 == 0. How many numbers are printed?
- 5
- 4
- 6
- 20
Show answer
Answer: A. The multiples of 4 up to 20 are 4, 8, 12, 16 and 20, which is 5 numbers.
-
15. How many times does the body of a loop run for I from 3 to 15 step 3?
- 4
- 13
- 5
- 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".
Sign in to keep track of the lessons you finish.