ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'a1b2c3' letters = ''.join(c for c in s if c.isalpha()) digits = sum(int(c) for c in s if c.isdigit()) print(letters, digits)
- A. abc 6
- B. abc 123
- C. a1b2c3 6
- D. abc 0
Correct answer: A. abc 6
isalpha keeps the letters and isdigit keeps the digits. The digits 1, 2 and 3 sum to 6.
More Python Programming questions
- What is printed? python def f(a, args, key=None, kw): return (a, args, key, sorted(kw)) print(f(1, 2, 3, key='k', z=0, y=9))
- What is printed? python print(bool(0.0), bool(-0.0), bool(1e-300), bool(float('nan')))
- What is printed? python print(sum(i i for i in range(1, 4)), sum(i 2 for i in range(1, 4)) == 14)
- What is printed? python print(round(1234.5678, -2), round(-1.5), round(-2.5), round(0.1 + 0.2, 1))
- What is printed? python import heapq rooms = [] for start, end in sorted([(1, 4), (2, 3), (3, 5)]): if rooms and rooms[0] <= start…
- What is printed? python print(' '.join(str(x) for x in range(3, 0, -1)), ' '.join(map(str, [])) == '')