ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print('%d items at %.1f%%' % (3, 12.345), '%5.2f|' % -1.005, '%08.3f' % -3.14159)- A. 3 items at 12.3% -1.01| -003.142
- B. 3 items at 12.4% -1.00| -003.142
- C. 3 items at 12.3% -1.00| -003.141
- D. 3 items at 12.3% -1.00| -003.142
Correct answer: D. 3 items at 12.3% -1.00| -003.142
%.1f of 12.345 gives 12.3, and -1.005 is stored just above its midpoint, so %5.2f shows -1.00 with the midpoint rounded down. %08.3f pads with zeros after the sign to width 8.
More Python Programming questions
- What is printed? python print(int('12') 2 3, float('12e3') // 1000, float('1000.5e1'))
- What is printed? python import math print(math.gcd(-12, 18), math.gcd(12, -18), math.lcm(-4, 6), math.gcd(0, 0))
- What is printed? python def digitssum(n): return sum(int(c) for c in str(abs(n))) print(digitssum(-9075), digitssum(1020), digitssum(0))
- What is printed? python x = 1020 + 1 y = float(x) print(int(y) == x, int(y) - x, y == 1020, float(x) == y)
- What is printed? python import math print(math.floor(1e300) == 10300, math.floor(1e300) == int(1e300), round(1e300) == 10300)
- What is printed? python print(0.1 + 0.2 != 0.3, (0.1 + 0.2) - 0.3 < 1e-16, abs((0.1 + 0.2) - 0.3) <= 5e-17)