如何计算水仙花数

今天搞了一个小时左右,只把水仙花程序看懂了。明天有空继续。。。

python基础--除法、地板除、取余

https://blog.csdn.net/legend818/article/details/77195545?ref=myread

Python: 问题贴之水仙花数

http://bbs.fishc.com/thread-93848-1-1.html

for i in range(100, 1000):
sum = 0
temp = i
while temp:
sum = sum + (temp%10) ** 3
temp //= 10 # 注意这里要使用地板除哦~
if sum == i:
print(i)

 

for 数 in range(100, 1000):
立方和 = 0
商 = 数
while 商:
商,余 = divmod(商,10)
立方和 += 余**3

if 立方和 == 数:
print(数)

猜你喜欢

转载自www.cnblogs.com/jiangkeji/p/9230445.html
今日推荐