โ† All HACKERRANK Flashcard Decks

Scalar Types and Operators 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 Scalar Types and Operators flashcards as text
  1. What is the result of `round(2.675, 2)` in Python 3?

    Answer: 2.67

    Due to floating-point representation, `2.675` is stored as slightly less than `2.675`, so `round()` returns `2.67`.

  2. Which of the following will raise a `TypeError` in Python?

    Answer: '5' + 3

    Python does not implicitly convert strings to numbers, so concatenating a string with an int raises a `TypeError`.

  3. What is the value of `abs(-7.5)`?

    Answer: 7.5

    `abs()` returns the absolute (non-negative) value of its argument, preserving the float type.

  4. What does `bool(0.0)` return?

    Answer: False

    Any numeric zero (`0`, `0.0`, `0j`) is falsy in Python and converts to `False`.

  5. What is the result of `2 ** 3 ** 2` in Python?

    Answer: 512

    Exponentiation is right-associative, so this evaluates as `2 ** (3 ** 2)` = `2 ** 9` = `512`.

  6. What type does Python assign to the literal `1_000_000`?

    Answer: int

    Python allows underscores as visual separators in numeric literals; `1_000_000` is simply the integer `1000000`.

  7. What is the output of `divmod(17, 5)`?

    Answer: (3, 2)

    `divmod(a, b)` returns a tuple `(a // b, a % b)`; for `17` and `5` that is `(3, 2)`.