ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(float('-0') == 0, str(float('-0')), str(0 * -1.0), 0.0 * -1)- A. True -0.0 -0.0 -0.0
- B. False -0.0 -0.0 -0.0
- C. True 0.0 0.0 1.0
- D. True -0.0 -0.0 0
Correct answer: A. True -0.0 -0.0 -0.0
Negative zero compares equal to zero, and str() of a negative zero float keeps the minus sign. Multiplying a float by -1 gives -0.0 when the other factor is zero.
More Python Programming questions
- What is printed? python print(1 < 2 < 3 < 4 == 4.0, 4 == 4.0 != 5, 1 < 3 > 2 < 2)
- What is printed? python print(oct(0o17 + 0b11), 0x10 | 0o7, 10 + 0x1)
- What is printed? python print('x'.center(4, '-') + '|', '7'.zfill(3) + '|', '-7'.zfill(4))
- What is printed? python print(max(3, 3.5, 2), min('b', 'a', 'c'), max([1, 2], [1, 3]))
- What is printed? python print(len(str(9 20)), str(9 20)[0], sum(map(int, str(9 20))) % 9)
- What is printed? python from fractions import Fraction print(Fraction('1.5'), Fraction('3/6'), float(Fraction('1/3')) == 1/3…