Python: How to determine whether a number is a daffodil number?

1. Problem

Insert picture description here

2. Procedure

def daf(numb1):
    if numb1 >= 100:
        pass
    else:
        print('请输入一个大于100的正整数')
    numb2 = str(numb1)
    lenargs = len(numb2)
    sum = 0
    for i in range(lenargs):
        sum = sum + int(numb2[i])**3
    #print(sum)

    if sum == numb1:
        print('%s是水仙花数' % numb1)
    #else:
    #    print('%s不是水仙花数' % numb1)

nummax = 1000
for i in range(100,nummax+1):
    daf(i)

3. Note:

Here, the input number is converted into a string format, and each unknown number is directly queried to identify the size of a tens of thousands of digits.

Guess you like

Origin blog.csdn.net/qq_40797015/article/details/113872160