用python写一个代码,实现:输入一个三位正整数abc,如果满足a^3+b^3+c^3=abc,则该数是水仙花数。例如123不等于1+8+27所以123不是水仙花数。
时间: 2024-05-21 08:11:42 浏览: 22
好的,以下是Python代码实现:
num = input("请输入一个三位正整数:")
a = int(num[0])
b = int(num[1])
c = int(num[2])
if a**3 + b**3 + c**3 == int(num):
print(num + "是一个水仙花数!")
else:
print(num + "不是一个水仙花数。")
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)