ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
w = 7
print(f"{'x':>{w}}|{3.0:g}|{1e-5:.0e}|{0.5:.0%}|{-3:+d}|{12:08b}")- A. x |3.0|1e-05|50%|-3|1100
- B. x|3|1e-05|50%|-3|00001100
- C. x|3|1e-5|50%|+-3|00001100
- D. x|3.0|0.00001|0.5%|-3|00001100
Correct answer: B. x|3|1e-05|50%|-3|00001100
Nested {w} sets the width to 7. :g drops trailing zeros, .0e gives one significant digit in exponent form, .0% multiplies by 100, + forces a sign (already '-'), and 08b pads binary to 8 digits.
More Python Programming questions
- What is printed? python print(int(True), int("0b101", 0), int("0o17", 0), int("ff", 16), int(" 12n"), int(" 0x10 ", 16))
- What is printed? python from fractions import Fraction as F from decimal import Decimal as D print(F(1, 3) + F(1, 6), D("0.1") + D("0.2")…
- What is printed (Python 3.12 or later)? python from functools import reduce xs = [0.1] 10 print(sum(xs) == 1.0, reduce(lambda a, b: a + b…
- What is printed? python nan = float("nan") print(max(nan, 1), max(1, nan), min(nan, 1), nan in {nan})
- What is printed? python print(max([1, 2], [1, 2, 0]), min("Z", "a", ""), sorted([True, 0, -1, 0.5]), max(3, 3.0), max(3.0, 3))
- What is printed? python print(bin(-5), (-5).bitlength(), ~5, -5 >> 1, -5 & 0b111, 5 ^ -1)