之前看到这个题,结合自己学习的和网上大家的经验真的写了下面这个长chou的:
#一个个算
nums = eval(input('请输入:'))
a = nums//10000
b = nums%10000//1000
c = nums%1000//100
d = nums%100//10
e = nums%10
if a!=0:
print(f'{nums}是一个5位数。{e}{d}{c}{b}{a}')
if a == 0 and b!=0:
print(f'{nums}是一个4位数。{e}{d}{c}{b}')
if a==0 and b==0 and c!=0:
print(f'{nums}是一个3位数。{e}{d}{c}')
if a==0 and b==0 and c==0 and d!=0:
print(f'{nums}是一个2位数。{e}{d}')
if a==0 and b==0 and c==0 and d==0 and e!=0 :
print(f'{nums}是一个1位数。{e}')
上面的太长太麻烦,在牛客上看见一个下面的表达,很简单,分享给大家:
#其实可以两句代码搞定
nums = input('')
print(f'{nums}是一个{len(nums)}位数。\n逆序输出为:{nums[::-1]}')