ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sum(x for x in range(1, 11) if x % 2 == 0) - sum(x for x in range(1, 11) if x % 2))
- A. -15
- B. 55
- C. 5
- D. 25
Correct answer: C. 5
The even numbers 2 to 10 sum to 30 and the odd numbers 1 to 9 sum to 25, so the difference is 5.
More Python Programming questions
- What is printed? python print('a,b,,c'.split(','), 'a b'.split())
- What is printed? python t = (1, 2) t += (3,) print(t, len(t))
- What is printed? python print(abs(-0), abs(-2.5), -(-3))
- What is printed? python print(hex(255), oct(8), bin(-5))
- What is printed? python print(chr(0x41), ord('n'))
- What is printed? python from collections import Counter a = [1, 1, 2, 3, 3] c = Counter(a) print(sum(c[x] c[4 - x] for x in c))