ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(int(3.9999999999999999), int(-3.7), round(-3.7))
- A. 3 -3 -4
- B. 4 -4 -4
- C. 4 -3 -4
- D. 4 -3 -3
Correct answer: C. 4 -3 -4
The literal 3.9999999999999999 is the same double as 4.0, so int gives 4. int truncates toward zero, giving -3, while round(-3.7) rounds to the nearest integer, giving -4.
More Python Programming questions
- What is printed? python print(hash(1) == hash(1.0), hash(True) == 1, {1: 'a', 1.0: 'b', True: 'c'})
- What is printed? python print(0.1 3 == 0.3, 0.1 3, 0.3 3 == 0.9)
- What is printed? python inf = float('inf') print(inf > 10400, inf - inf == 0, -inf < -10400, inf == inf)
- What is printed? python print(len(str(21000)), sum(int(d) for d in str(2100)))
- What is printed? python import math print(math.gcd(0, -6), math.lcm(4, 6), -7 % -3, math.lcm(0, 5))
- What is printed? python x = 6 print(x & (x - 1), x & -x, (x ^ (x >> 1)) & 1, x.bitlength(), (-x).bitlength())