代码:
if __name__ == '__main__':
while True:
num = input('二位数')
if len(num) == 2:
try:
int(num)
break
except:
pass
print('请输入正确的二位数')
print(f'你输入的二位数是{num}')
new_num = []
for i in range(10, int(num) + 1):
if int(str(i)[1]) < int(str(i)[0]):
new_num.append(i)
print(f'从10到{num}的所有个位数小于十位数的数有:', new_num)
result = 0
for i in new_num:
result += i
print('所有数之和:', result)
结果:
二位数99
你输入的二位数是99
从10到99的所有个位数小于十位数的数有: [10, 20, 21, 30, 31, 32, 40, 41, 42, 43, 50, 51, 52, 53, 54, 60, 61, 62, 63, 64, 65, 70, 71, 72, 73, 74, 75, 76, 80, 81, 82, 83, 84, 85, 86, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98]
所有数之和: 2970
|