# coding=utf-8
"""给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字"""
everyNum = []
def getNum():
try:
num = int(input("请输入一个不多于5位的正整数:"))
except Exception as e:
print(e)
print("请重新输入")
getNum()
else:
if num > 99999 or num < 0:
print("请重新输入")
getNum()
else:
return num
print("输入成功!")
def getEveryNum(x):
a = x // 10000
b = x % 10000 // 1000
c = x % 1000 // 100
d = x % 100 // 10
e = x % 10
everyNum.append(a)
everyNum.append(b)
everyNum.append(c)
everyNum.append(d)
everyNum.append(e)
if a != 0:
print("五位数")
elif b != 0:
print("四位数")
elif c != 0:
print("三位数")
elif d != 0:
print("二位数")
else:
print("一位数")
def printNum(num):
print("倒序输出:", end="\t")
for i in reversed(num):
if i == 0:
continue
else:
print(i, end="\t")
if __name__ == '__main__':
num = getNum()
getEveryNum(num)
printNum(everyNum)
# 加油