ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = 'a'
for i in range(3):
s = s + s[::-1] + str(i)
print(s, len(s))- A. aa00aa1aa00aa2 14
- B. aa00aa11aa00aa2 14
- C. aa00aa11aa00aa2 15
- D. aa00aa11aa00aa 15
Correct answer: C. aa00aa11aa00aa2 15
Each pass makes the new string the old one, its reverse, and a digit, so the length goes 1, 3, 7, 15. Tracking the length this way avoids simulating the string.
More Python Programming questions
- What is printed? python t = (1, 2, 3) t += (4,) u = t t = 2 print(t, u, t is u, len(t) len(u))
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)
- What is printed? python print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')
- What is printed? python a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)
- What is printed? python print(pow(7, 222, 10), pow(7, 222, 1000), 7222 % 1000, pow(-7, 3, -5))
- What is printed? python print(int(True) + int('0b11', 2), int(3.7 // 1), int(-0.5), round(-0.5), round(0.5))