ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print('%.2f' % 2.675, '%.2f' % 2.665, round(2.665, 2), format(2.5, '.0f'), format(0.125, '.2f'))- A. 2.68 2.67 2.67 2 0.12
- B. 2.67 2.66 2.67 2 0.12
- C. 2.67 2.67 2.67 3 0.13
- D. 2.67 2.67 2.67 2 0.12
Correct answer: D. 2.67 2.67 2.67 2 0.12
Each decimal literal is stored as the nearest binary double, and the rounding is done on that stored value. 2.675 is stored a little below the midpoint, so it rounds down, and 0.125 is exact, so it is a tie and goes to the even digit.
More Python Programming questions
- What is printed? python print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)
- What is printed? python from decimal import Decimal print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) ==…
- What is printed? python from fractions import Fraction print(Fraction(1, 3) + Fraction(1, 6), Fraction(0.5), Fraction('0.1') +…
- What is printed? python print(int('0b101', 0), int('0o17', 8), int('z', 36), int('-0'), int('+7'))
- What is printed? python print(str(True) + str(1 == 1.0), True + True, '3' True, [0] True)
- What is printed? python print(max('apple', 'banana', key=len), max('pear', 'fig', key=len), min('bb', 'aa', 'c', key=len))