课后作业
1. 编写一个程序,求 100~999 之间的所有水仙花数。
如果一个 3 位数等于其各位数字的立方和,则称这个数为水仙花数。例如:153 = 1^3 + 5^3 + 3^3,因此 153 就是一个水仙花数
for i in range(100, 1000):
sum = 0
temp = i
while temp:
sum = sum + (temp%10) ** 3
temp //= 10 # 注意这里要使用地板除哦~
if sum == i:
print(i)
这个答案没看懂是什么意思;有大神解答一下吗 请见:
https://fishc.com.cn/forum.php?mod=viewthread&tid=163077
https://fishc.com.cn/forum.php?mod=viewthread&tid=93848
PS:善用论坛的【搜索】功能 zltzlt 发表于 2020-4-15 21:05
请见:
https://fishc.com.cn/forum.php?mod=viewthread&tid=163077
蟹蟹
页:
[1]