猫史档案馆


【Python作品分享】大数据分解质因数【作品秀】

用户:林家宇爱编程(小号)林家宇爱编程(小号)查看:0 回复:1 评论:0 创建时间:2022-04-03T15:48:50


【作品展示】

center_image

 

【作品介绍】

这是一款分解质因数的程序!

 

【作品源代码】

import math
import time
while True:
    try:

        number = int(input("输入一个整数(按0退出):"))
        if number == 0:
            print("谢谢使用!")
            time.sleep(1)
            break
        else:
            list1 = []

            def getChildren(num):
                isZhishu = True
                for i in range(2, int(math.sqrt(1 + num)) + 1):
                    if num % i == 0 and i != num:
                        list1.append(i)
                        isZhishu = False
                        getChildren(num / i)
                        break
                if isZhishu:
                    list1.append(num)
            getChildren(number)
            a = ""
            for i in list1:
                v = int(i)
                a += str(v)
                a += "×"
            print(a[:-1])
            time.sleep(0.2)
    except ValueError:
        print("输入错误,请重新输入!")
    except OverflowError:
        print("数值过大,请重新输入!")

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
BlueHackerBlueHacker

判断是否为质数用的是什么算法?

点赞0


评论