def add(long: str ,short: str) -> str: over: int = 0 result: str = "" for i in range(1, len(long) + 1): if i > len(short) and over: num_sum: int = int(long[-i]) + over elif i > len(short) and not over: result = long[:-i + 1] + result break else: num_sum: int = int(long[-i]) + int(short[-i]) + over result = str(num_sum % 10) + result over = int(num_sum / 10) if over: result = "1" + result return result if __name__ == "__main__": a: str = input() b: str = input() if len(a) > len(b): result = add(a, b) else: result = add(b, a) print(result)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | def add(long: str ,short: str) -> str: over: int = 0 result: str = "" for i in range(1, len(long) + 1): if i > len(short) and over: num_sum: int = int(long[-i]) + over elif i > len(short) and not over: result = long[:-i + 1] + result break else: num_sum: int = int(long[-i]) + int(short[-i]) + over result = str(num_sum % 10) + result over = int(num_sum / 10) if over: result = "1" + result return result if __name__ == "__main__": a: str = input() b: str = input() if len(a) > len(b): result = add(a, b) else: result = add(b, a) print(result) |