SHS Computing · Year 2

Python Functions, Conditions, Loops and Recursion practice questions

Variable naming rules and snake_case, primitive and complex data types, comments, defining and calling functions with parameters and return values, arithmetic including modulus, comparison and logical operators, if, if-else and if-elif-else statements, for loops with range, while loops, recursion and base cases, and building a simple calculator.

25 questions in this topic: 2 recall, 6 applying skills and concepts, 14 strategic thinking and 3 extended thinking. Every one carries a written explanation.

Sample questions

5 of 25 questions in this topic. Sign up to answer them and see the explanations.

  1. Question 1Skills & concepts

    When is a while loop more suitable than a for loop?

    • aWhen a task must be repeated exactly ten times, such as printing the numbers 1 to 10
    • bWhen the number of repetitions is not known in advance, such as asking until a correct password is typed
    • cWhen the program must loop through every single item of a list in order from the first one to the last
    • dWhen the loop must never stop, since for loops cannot be used without a range at all
  2. Question 2Strategic thinking

    Score = 85. The code is: if Score > 50: print("pass") elif Score > 80: print("merit") else: print("fail"). What is printed?

    • amerit
    • bpass
    • cpass and merit
    • dfail
  3. Question 3Strategic thinking

    What does this code output? x = 15; print(x % 2 == 0)

    • aTrue
    • b1
    • cFalse
    • d7
  4. Question 4Skills & concepts

    Which variable name follows Python's snake_case style?

    • aTotalPrice
    • btotal price
    • ctotal-price
    • dtotal_price
  5. Question 5Strategic thinking

    What does this code output? n = 1; while n < 20: n = n * 3; then print(n)

    • a27
    • b9
    • c18
    • d20

Answer these and 20 more on Python Functions, Conditions, Loops and Recursion

Free account. Instant marking, a written explanation for every question.

Start practising free

More Computing Year 2 topics

All Computing topics