Decisions and Loops

38 MCQs Covers if, if-else, elif, short-hand and nested decisions. Also covers while and for loops, range(), break/continue and code-output questions

MCQs

38 questions · 30 min · 38 marks

Want to try first? Take the free Computer Science test: SDLC and Waterfall Model

Sample questions

The first 5 of 38. Try each one, then tap to see the answer.

  1. Question 1

    What is the output of the following code? temperature = 35 | if temperature > 30: | print("It's hot")

    • AIt's cold
    • BIt's hot
    • CNothing
    • DError
    Show answer

    Answer: B

    35 > 30 is True, so the message is printed. (Textbook MCQ 19.)

  2. Question 2

    Which statement checks multiple conditions in Python?

    • Aif
    • Bfor
    • Cwhile
    • Delif
    Show answer

    Answer: D

    elif lets you test further conditions after an if.

  3. Question 3

    Which loop runs until a condition becomes false?

    • Awhile
    • Bfor
    • Cloop
    • Dif
    Show answer

    Answer: A

    A while loop repeats as long as its condition is True.

  4. Question 4

    What does the range(5) function return?

    • ANumbers from 1 to 5
    • B5 only
    • CNumbers from 0 to 4
    • DNothing
    Show answer

    Answer: C

    range(5) starts at 0 and stops before 5.

  5. Question 5

    Which keyword is used to skip the rest of the loop body and move to the next iteration?

    • Astop
    • Bcontinue
    • Cskip
    • Dnext
    Show answer

    Answer: B

    continue skips the remaining statements of the current iteration.

More tests in Python Programming

Practise with a free account

Save your scores, see which chapters need work, and keep a notebook of every question you got wrong.

Create free account