← All HACKERRANK Flashcard Decks

Control Flow and Looping Flashcards

7 cards from real HACKERRANK practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Control Flow and Looping flashcards as text
  1. What is the output of: ```python for i in range(5): if i == 3: break else: print('no break') print('end') ```

    Answer: end

    The break at i==3 prevents the else clause from executing, so only 'end' is printed.

  2. What type does `range(5)` return in Python 3?

    Answer: range object

    In Python 3, range() returns a range object (lazy sequence), not a list.

  3. What is the output of this code? ```python x = 0 while x < 5: x += 1 if x == 3: continue print(x) ```

    Answer: 1 2 4 5

    continue skips the print when x == 3, so 3 is not printed but all other values 1-5 are.

  4. What does `any([False, False, True, False])` return?

    Answer: True

    any() returns True if at least one element is truthy — here True is present in the list.

  5. What is the result of: ```python total = sum(x**2 for x in range(4)) print(total) ```

    Answer: 14

    0²+1²+2²+3² = 0+1+4+9 = 14.

  6. Which control flow statement immediately terminates the current function and optionally returns a value?

    Answer: return

    return exits the current function, optionally passing a value back to the caller.

  7. What is the output of: ```python for i in range(3): for j in range(3): if j == 1: break print(i, j) ```

    Answer: 0 1, 1 1, 2 1

    break exits the inner loop when j==1, so after each inner loop j is 1 when it breaks.