ProgrammingHardTCS NQT · Infosys
What is printed on the second line?
What is printed on the second line?
a, b = -13, 4 print(a // b, a % b, a // b * b + a % b == a) print(int(a / b), int(-3.25), -3.25 // 1)
- A. -4 -3 -4.0
- B. -3 -3 -3.0
- C. -3 -4 -4.0
- D. -3 -3 -4.0
Correct answer: D. -3 -3 -4.0
int() truncates toward zero, so int(-3.25) is -3, while floor division of -3.25 by 1 rounds down to -4.0. Mixing int() with // is a common source of mistakes.
More Python Programming questions
- What is printed on the first line? python n = -17 print(n >> 2, n // 4, n & 3, n % 4) print(n << 1, (n << 1) >> 1 == n, ~n)
- What is printed on the first line? python x = 1 for in range(70): x = 2 print(x, x.bitlength(), x == 270) print(x.bitlength() - 1, (x…
- What is printed on the first line? python import math print(math.factorial(20) == 2432902008176640000, len(str(math.factorial(25))))…
- What is printed on the first line? python n = 264 print(n, n.bitlength(), hex(n - 1), oct(8), bin(5)) print(int(hex(n)[2:], 16) == n, -263…
- What is printed on the first line? python print(int('1' 19) + 1, 1018 10, 9223372036854775807 + 1 > 263 - 1) print(2100 // 298, (2100) >>…
- What is printed? python print(0b1111 ^ 0b1010 & 0b0110, (0b1111 ^ 0b1010) & 0b0110, 6 & 3 | 4 ^ 1)