Python语言生成水仙花数代码示例
作者:阮小七 时间:2022-11-16 18:17:48
水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。
本文将通过Python代码实现打印水仙花数,具体如下:
#水仙花数
#narcissistic number
#水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。
#(例如:1^3 + 5^3+ 3^3 = 153)
import math
import string
for x in range(1,10):
a=x*x*x
for y in range(0,10):
b=y*y*y
for z in range(0,10):
c=z*z*z
d=a+b+c
w='%d' %x+'%d' %y+'%d' %z
if d==int(w):
print('水仙花数:'+w+'\n')
运行结果:
来源:http://outofmemory.cn/code-snippet/83403/shuixianhua-shu
标签:python入门
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 用opencv实现图像修复和图像金字塔
2022-09-27 09:24:22
![](https://img.aspxhome.com/file/2023/9/83929_0s.png)
PHP PDOStatement::columnCount讲解
2023-06-04 22:24:39
SQL Server 2000如何设置会话上下文信息?
2010-05-18 18:33:00
Python真题案例之二分法查找详解
2023-09-23 01:39:07
![](https://img.aspxhome.com/file/2023/6/85376_0s.png)
分享一些非常实用的Python小技巧
2022-08-09 09:27:17
基于Python实现快递信息提取
2022-05-02 13:41:11
![](https://img.aspxhome.com/file/2023/0/126970_0s.jpg)
浅谈Python 钉钉报警必备知识系统讲解
2023-11-13 15:14:38
![](https://img.aspxhome.com/file/2023/7/75907_0s.png)
mysql的日期和时间函数
2024-01-22 12:46:18
MySQL 统计查询实现代码
2024-01-25 06:41:14
浅谈解除装饰器作用(python3新增)
2022-05-30 03:31:52
MySQL主从搭建(多主一从)的实现思路与步骤
2024-01-18 01:14:02
SQL Server 2016 CTP2.2安装配置方法图文教程
2024-01-18 19:04:29
![](https://img.aspxhome.com/file/2023/5/92735_0s.png)
python 生成正态分布数据,并绘图和解析
2022-02-11 07:14:00
![](https://img.aspxhome.com/file/2023/0/118760_0s.png)
关于Dreamweaver乱码问题的解决方案
2010-09-02 12:36:00
js array数组对象操作方法汇总
2024-05-08 10:10:37
php for 循环语句使用方法详细说明
2023-11-17 21:43:21
悟道Web标准:让W3C标准兼容终端
2009-10-11 16:40:00
浅谈图表参数化设计
2010-08-29 18:03:00
![](https://img.aspxhome.com/file/UploadPic/20108/29/01-56s.jpg)
简单了解Python write writelines区别
2023-06-16 14:00:28
PyTorch实现ResNet50、ResNet101和ResNet152示例
2023-10-16 05:44:39
![](https://img.aspxhome.com/file/2023/4/120404_0s.jpg)