怎样用Python将一个正整数分解质因数

 时间:2024-10-16 18:32:45

1、首先,右键点击【项目】,创建一个【Python】文件

怎样用Python将一个正整数分解质因数

2、接着,在右侧输入代码,代码写在【下一步】

怎样用Python将一个正整数分解质因数

3、然后,复制代码粘贴到文件中def reduceNum(n): print ('{} = '.format(n)) if not isinstance(n, int) or n <= 0 : print ('请输入一个正确的数字 !') exit(0) elif n in [1] : print ('{}'.format(n)) while n not in [1] : # 循环保证递归 for index in range(2, n + 1): if n % index == 0: n /= index # n 等于 n/index if n == 1: print (index) else : # index 一定是素数 print ('{} *'.format(index),) breakreduceNum(90)reduceNum(100)

怎样用Python将一个正整数分解质因数

4、随后,右键选择运行代码文件

怎样用Python将一个正整数分解质因数

5、最后,在最下面就可以看到运行结果了

怎样用Python将一个正整数分解质因数
  • python如何统计列表中元素个数?
  • Python编程:怎么将一个整数分解质因数
  • python一次性输入n个数
  • python创建列表
  • 如何将python中的列表转换成字符串
  • 热门搜索
    sunny怎么读 胃痛怎么办 徜徉怎么读 馄饨馅怎么调才好吃 隔夜茶为什么不能喝 怎么注销qq空间 移动怎么查话费 gucci怎么读 竺怎么读 紫砂壶怎么开壶