ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(int(2.675 * 100), round(2.675, 2))
- A. 267 2.68
- B. 268 2.67
- C. 267 2.67
- D. 268 2.68
Correct answer: C. 267 2.67
2.675 is stored as about 2.67499999999999982, so 2.675 * 100 is 267.49999999999997 and int truncates to 267. round uses the exact stored value, which is below the midpoint, so it gives 2.67.
More Python Programming questions
- What is printed? python print(-7.5 // 2, -7.5 % 2)
- What is printed? python print(pow(3, 0, 1), pow(3, 0), 0 0)
- What is printed? python x = [1, 2, 3, 4, 5] print(x[-1:-4:-1], x[::-1][:2], x[::2][-1])
- What is printed? python import bisect a = [3, 1, 2, 5, 4] seen = [] inv = 0 for x in a: inv += len(seen) - bisect.bisectright(seen, x)…
- What is printed? python print(float('nan') == float('nan'), float('inf') - float('inf') != float('inf') - float('inf'))
- What is printed? python try: print([1, 2] < (1, 2)) except TypeError as e: print(e)