12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转。
def fun1(a): arr = [] while a>0: t = a % 10 a = int(a / 10) arr.append(t) return arr def fun2(a): n = len(a) - 1 s = 0 for i in a: s += i*(10**n) n -= 1 return s def resverse(a ,b): arr, brr = [], [] arrv = fun1(a) brrv = fun1(b) s1 = fun2(arrv) s2 = fun2(brrv) s = s1 + s2 srrv = fun1(a+b) sv = fun2(srrv) if sv == s: print(a+b) else: print('NO') while True: try: a, b = map(int, input().split()) resverse(a, b) except: break