首页 > 代码库 > 输入12345,输出54321

输入12345,输出54321

输入123456,输出654321,两个都是int类型;

输入的参数为num/out,int类型;

返回值为int类型。

第一种:(传入的值为正整数)

    out = 0    while num:        out = out * 10 + num % 10        num /= 10        return out

第二种:

def reserve_num(num):    remainder = 0    remainder = num %10    while num>1:        num /= 10        if num > 0:            remainder = remainder*10 + num %10    return remainder

运行结果:

if __name__ == ‘__main__‘:      print reserve_num(543211)  #输出112345

 

输入12345,输出54321