โ† 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 `complex(2, 3) + complex(1, -1)`?

    Answer: (3+2j)

    Complex addition adds real and imaginary parts separately: `(2+1)` and `(3-1)` give `3+2j`.

  2. Which of the following is NOT a valid Python integer literal?

    Answer: 0d255

    Python supports hex (`0x`), octal (`0o`), and binary (`0b`) literals, but there is no decimal prefix `0d`.

  3. What does `float('inf') > 10**100` return?

    Answer: True

    `float('inf')` represents positive infinity in Python and is greater than any finite number.

  4. What is the value of `0.1 + 0.2 == 0.3` in Python?

    Answer: False

    Floating-point arithmetic is inexact; `0.1 + 0.2` evaluates to `0.30000000000000004`, not exactly `0.3`.

  5. What is the result of `int(True) + int(False) * 5`?

    Answer: 1

    `int(True)` is `1` and `int(False)` is `0`; operator precedence makes this `1 + (0 * 5)` = `1`.

  6. Which function returns the number of bits required to represent an integer in binary?

    Answer: int.bit_length()

    `int.bit_length()` returns the number of bits needed, excluding the sign and leading zeros.

  7. What is the output of `(-7) % 3` in Python?

    Answer: 2

    Python's modulo always returns a non-negative result when the divisor is positive; `(-7) % 3 = 3 - (7 % 3) = 2`.