ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{3.14159:.2}', f'{"abc":.2}', f'{0.5:.0%}')- A. 3.1 ab 50%
- B. 3.14 ab 50%
- C. 3.1 abc 50%
- D. 3.1 ab 0.5
Correct answer: A. 3.1 ab 50%
For a float, .2 means two significant digits, so 3.14159 gives 3.1. For a string it truncates to two characters, and the percent type multiplies by 100.
More Python Programming questions
- What is printed? python from fractions import Fraction print(Fraction(1, 2) + 0.5 == 1, Fraction(1, 3) 3 == 1, type(Fraction(1, 2) +…
- What is printed? python print(max(-3, 2, key=abs), min(-3, 2, key=abs), sorted([-3, 2, -2], key=abs), sorted([-3, 2, -2], key=lambda v…
- What is printed? python print(1 - 0.9 == 0.1, round(1 - 0.9, 1) == 0.1, 1 - 0.9 > 0.09, 1 - 0.9)
- What is printed? python print(len('a1b22c333'.split('2')), ''.join(c for c in 'a1b22c333' if c.isdigit()), len('a1b22c333'))
- What is printed? python print(0.1 + 0.1 + 0.1 == 0.3, 0.1 3, 0.3 / 0.1, int(0.3 / 0.1))
- What is printed? python print(format(0.5, '.0f'), format(1.5, '.0f'), format(2.5, '.0f'), format(-0.5, '.0f'))