Saudi Secondary School Certificate · Computer Science and Digital Skills

Python programming and algorithms

40 practice questions, each with the answer and an explanation.

Practise Python programming and algorithms now

Random questions from this topic, one at a time. You see the answer and the explanation straight after each one.

All 40 questions

  1. What is the output of `print([x**2 for x in range(6) if x % 2 == 0])`?
  2. What is the output of `print([x**2 for x in range(4) if x % 2 == 0])`?
  3. What is the output of `print([x**2 for x in range(5) if x % 2 == 0])`?
  4. What is the output of `print([x**2 for x in range(4) if x % 3 == 0])`?
  5. What is the output of `print([x**2 for x in range(7) if x % 2 == 0])`?
  6. What does `'algorithm'[3:4]` return in Python?
  7. What does `'network'[0:5]` return in Python?
  8. What does `'security'[0:8]` return in Python?
  9. What does `'computer'[0:8]` return in Python?
  10. What is the value of `s` after: `s = 0` / `for i in range(2, 8, 2): s += i`?
  11. What is the value of `s` after: `s = 0` / `for i in range(2, 10, 4): s += i`?
  12. What is the value of `s` after: `s = 0` / `for i in range(2, 12, 2): s += i`?
  13. What is the value of `s` after: `s = 0` / `for i in range(3, 11, 4): s += i`?
  14. What is the value of `s` after: `s = 0` / `for i in range(3, 9, 2): s += i`?
  15. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(12)?
  16. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(9)?
  17. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(10)?
  18. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(8)?
  19. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(11)?
  20. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(7)?
  21. A function returns 0 for n = 0, 1 for n = 1, and fib(n-1) + fib(n-2) for larger n. What is fib(6)?
  22. What is the decimal number 177 in binary?
  23. What is the decimal number 133 in binary?
  24. What is the binary number 1010001 in decimal?
  25. What is the binary number 1010 in decimal?
  26. What is the binary number 10010001 in decimal?
  27. What is the binary number 1100111 in decimal?
  28. What is the binary number 10011001 in decimal?
  29. What is the decimal number 49 in hexadecimal?
  30. What is the decimal number 148 in hexadecimal?
  31. What is the decimal number 175 in hexadecimal?
  32. What is the decimal number 190 in hexadecimal?
  33. What is the maximum number of comparisons needed by binary search on a sorted list of 512 items?
  34. What is the maximum number of comparisons needed by binary search on a sorted list of 16 items?
  35. What is the maximum number of comparisons needed by binary search on a sorted list of 128 items?
  36. What is the maximum number of comparisons needed by binary search on a sorted list of 1024 items?
  37. What is the maximum number of comparisons needed by binary search on a sorted list of 256 items?
  38. What is the maximum number of comparisons needed by binary search on a sorted list of 32 items?
  39. What is the maximum number of comparisons needed by binary search on a sorted list of 64 items?
  40. What is the output of a NOR gate when A = 0 and B = 0?

Ready for the full Saudi Secondary School Certificate test?