ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('{:e}'.format(1234.5), '{:.3g}'.format(1234567), '{:g}'.format(0.0001), '{:g}'.format(0.00001))- A. 1.2345e+03 1.23e+06 0.0001 1e-05
- B. 1.234500e+03 1.23e+6 0.0001 1e-5
- C. 1.234500e+03 1.23e+06 0.0001 1e-05
- D. 1.234500e+03 1.23e+06 0.0001 0.00001
Correct answer: C. 1.234500e+03 1.23e+06 0.0001 1e-05
The e format uses six decimals by default. .3g keeps three significant digits and switches to exponent form for large values, while g uses exponent form for values below 1e-4.
More Python Programming questions
- What is printed? python print('é'.encode('ascii', 'replace'), 'é'.encode('ascii', 'ignore'), b'hxc3xa9llo'.decode('ascii', 'ignore')…
- What is printed? python print(10 50 // 3 20 % 100, len(bin(10 50)) - 2, (10 50).bitlength())
- What is printed? python print(1 < 2 < 3 == 3.0 != 4, 1 < 2 > 3, (1 < 2) > 3, 'a' < 'b' < 'a')
- What is printed? python x = 0b1011 print(x & ~(1 << 1), x ^ (1 << 2), x | (1 << 4), (x >> 1) & 1)
- What is printed? python words = ['bb', 'a', 'ccc', 'aa'] print(sorted(words, key=lambda w: (-len(w), w)))
- What is printed? python pairs = [(1, 'b'), (1, 'a'), (0, 'c')] print(sorted(pairs, key=lambda p: p[0]), sorted(pairs))