ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
parts = []
for i in range(3):
parts.append(str(i) * i)
print(repr(''.join(parts)), ''.join(map(str, range(3))))- A. '122' 012
- B. '1220' 012
- C. '122' 210
- D. '022' 012
Correct answer: A. '122' 012
Multiplying a string by 0 gives the empty string, so the parts are '', '1' and '22'. They join to '122', and range(3) mapped to str and joined gives '012'.
More Python Programming questions
- What is printed? python print(int('07'), int('07')) try: print(int('07', 0)) except ValueError: print('leading zero')
- What is printed? python x = 1 / 3 print(x 3 == 1, 1 - 2 / 3 == 1 / 3, 0.1 + 0.2 - 0.3 == 0)
- What is printed? python s = 'ab' 2 + 'c' print(s.count('ab'), s.count('aba'), s.find('b', 2), s.rfind('ab'), s.index('c'))
- What is printed? python print('abc'.partition('x'), 'a=b=c'.partition('='), 'a=b=c'.rpartition('='))
- What is printed? python s = 'abcdefgh' print(s[::-2], s[1::3], s[-3:-6:-1], s[::-1][::2])
- What is printed? python print('%05.1f|%x|%o|%e' % (3.14159, 255, 8, 12345.678))