因为 3/2 = 1.5,但是 3//2 = 1
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def is_sxh(n):
... return (n//100)**3 + (n//10%10)**3 + (n%10)**3 == n
...
>>> for i in range(100, 1000):
... if is_sxh(i):
... print(i)
...
153
370
371
407
>>>
for i in range(100,1000):
for a in range(1,10):
for b in range(0,10):
for c in range(0,10):
if(i==a**3 + b**3 + c**3) and (i==100*a+10*b+c):
print(i)
查找水仙花数:
for i in range(100,1000):
a=i//100
b=(i%100)//10
c=(i%100)%10
if i == a*a*a+b*b*b+c*c*c:
print(i)