ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(float(3) / 2 == 1.5, 3 // 2.0, 3 / 2.0 // 1)
- A. True 1 1.0
- B. True 1.0 1
- C. False 1.0 1.0
- D. True 1.0 1.0
Correct answer: D. True 1.0 1.0
Division with / always gives a float, and // with a float operand gives a float too. The results are 1.5 == 1.5, then floor(1.5) = 1.0 in both cases.
More Python Programming questions
- What is printed? python print(round(3.14159, 3), round(2.5e-7, 7), round(123.456, -1), round(-0.0001, 2))
- What is printed? python print('Hello World'.swapcase().title(), 'tEST'.capitalize(), 'x'.isalpha(), '1.5'.isdigit(), '١٢'.isdigit())
- What is printed? python print('ab' in 'cabd', '' in 'abc', 'abc'.index(''), len('abc'[3:]), len('abc'[4:]))
- What is printed? python print(sum(map(int, str(220))), len(str(350)), str(105)[::-1].count('0'))
- What is printed? python print(float('0.1') + float('0.2') == float('0.30000000000000004'), 0.1 + 0.2 == 0.30000000000000004)
- What is printed? python print(5 // 0.4, 5 % 0.4, 0.4 12 == 4.8, 5 / 0.4)