Python小白实例(八)——水仙花数

while True:
    num = input("please input number:")
    num = int(num)
    if 100 <= num <= 999:
        a = num // 100
        b = num % 100 // 10
        c = num % 10
        # print(a, b, c)
        sum = a ** 3 + b ** 3 + c ** 3
        if num == sum:
            notice = "  是水仙花数"
            print("The number %d" % (num) + notice)
        else:
            notice = "  不是水仙花数"
            print("The number %d" % (num) + notice)
            # print(num+notice)
    else:
        print("Your input is error,please reput:")

猜你喜欢

转载自blog.csdn.net/GT_Stone/article/details/80866394