ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
- A. 0.0 True -0.0 0.0
- B. 0.0 False -0.0 0.0
- C. -0.0 True 0.0 -1.0
- D. 0.0 True 1.0 0.0
Correct answer: A. 0.0 True -0.0 0.0
IEEE 754 zero has a sign, so str shows -0.0, yet -0.0 == 0.0 is True. Adding +0.0 to -0.0 under round-to-nearest gives +0.0.
More Python Programming questions
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), sum([0.1] 10, 0) == 1.0)
- What is printed? python print(int(3.9999999999999999), int(-3.7), round(-3.7))
- 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)))