猫史档案馆


【Python作品分享】水仙花数进阶版【作品秀】

用户:邢小陆邢小陆查看:93 回复:0 评论:0 创建时间:2020-08-12T17:02:48


【作品展示】

center_image

 

【作品介绍】

F**K

 

【作品源代码】

'''练习2成果包——水仙花数v2.0'''
'''
编写程序帮助阿短找到全部的水仙花数。查找范围为:100-999。

输入起始数,输入终止数,输出此范围内所有的水仙花数。
如:
Input:
输入起始数:100
输入终止数:999
Output:
153 是水仙花数
370 是水仙花数
371 是水仙花数
407 是水仙花数
'''

#判定一定范围内的水仙花数
head = int(input('输入起始数:'))
tail = int(input('输入终止数:'))
#外层添加主循环,依次处理范围内的每个数
while head <= tail:
    #将从范围内取到的数对应拿出,赋值给变量number
    number = str(head)
    i = 0
    total = 0
    while i < len(number):
        total += int(number[i]) ** 3
        i += 1
    if int(number) == total:
        print(number, '是水仙花数')
    #外层循环中的head处理
    head += 1

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页