logo

Question detail

Write a Python 3 subroutine called displayEvenTaskNumbers that receives a positive integer taskLimit. It must use iteration to examine the task numbers from 1 to taskLimit, and use selection to display only the even task numbers. Use at least one meaningful identifier and include a constant declaration for the starting task number. Briefly explain how sequence, selection and iteration are combined.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Write a Python 3 subroutine called displayEvenTaskNumbers that receives a positive integer taskLimit. It must use iteration to examine the task numbers from 1 to taskLimit, and use selection to display only the even task numbers. Use at least one meaningful identifier and include a constant declaration for the starting task number. Briefly explain how sequence, selection and iteration are combined.

Model answer

What a good answer should say

  • START_TASK_NUMBER = 1 def displayEvenTaskNumbers(taskLimit): for taskNumber in range(START_TASK_NUMBER, taskLimit + 1): if taskNumber % 2 == 0: print(taskNumber)

Explanation

Why this works

START_TASK_NUMBER is used as a named constant by convention. The statements in the subroutine execute in sequence.

The for loop provides iteration through the task numbers, and the if statement provides selection so that only even numbers are displayed. taskLimit and taskNumber are meaningful identifiers because they describe their purposes.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.