ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(sum(range(1, 101)) ** 2 - sum(i * i for i in range(1, 101)))
- A. 25164150
- B. 25502500
- C. 338350
- D. 25164151
Correct answer: A. 25164150
The square of the sum minus the sum of the squares is the classic Project Euler difference. 5050 squared is 25502500 and the sum of squares is 338350, so the difference is 25164150.
More Python Programming questions
- What is printed? python print(len(str(264)), sum(map(int, str(264))))
- What is printed? python print(all(int(c) % 2 == 0 for c in '24680'), any(c in 'aeiou' for c in 'rhythm'))
- What is printed? python print(''.join(c.upper() if i % 2 else c for i, c in enumerate('python')))
- What is printed? python print(' '.join(w[::-1] for w in 'hello big world'.split()))
- What is printed? python print(max(len(w) for w in 'the quick brown fox'.split()), [w for w in 'the quick brown fox'.split() if len(w) == 5])
- What is printed? python print(''.join(sorted('hello', key=lambda c: (c not in 'aeiou', c))))