python水仙花数

水仙花数是3位整数(100-199),它的各位数字立方和等于该数本身。请编写程序。
源代码:

print('100-199的水仙花数:')
for i in range(100,200):
    s = str(i)
    a = int(s[0])
    b = int(s[1])
    c = int(s[2])
    if a**3+b**3+c**3 == i :
        print(i,end=' ')


列出测试数据和实验结果截图:
python水仙花数_第1张图片

你可能感兴趣的:(Python实验,python)