def add_big_numbers(a, b): result = [0] * (max(len(a), len(b)) + 1) for i in range(len(a)): result[i] += int(a[i]) for i in range(len(b)): result[i] += int(b[i]) for i in range(0, len(result)): if result[i] >= 10: result[i] -= 10 result[i + 1] += 1 if result[-1] == 0: result.pop() return ''.join(str(x) for x in reversed(result)) if __name__=='__main__': #a = ''.join(reversed(input().strip())) #b = ''.join(reversed(input().strip())) a = ''.join(reversed(input())) b = ''.join(reversed(input())) result = add_big_numbers(a, b) print(result)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | def add_big_numbers(a, b): result = [0] * (max(len(a), len(b)) + 1) for i in range(len(a)): result[i] += int(a[i]) for i in range(len(b)): result[i] += int(b[i]) for i in range(0, len(result)): if result[i] >= 10: result[i] -= 10 result[i + 1] += 1 if result[-1] == 0: result.pop() return ''.join(str(x) for x in reversed(result)) if __name__=='__main__': #a = ''.join(reversed(input().strip())) #b = ''.join(reversed(input().strip())) a = ''.join(reversed(input())) b = ''.join(reversed(input())) result = add_big_numbers(a, b) print(result) |