Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
FullStackPark
Knowledge
Repository navigation
Code
Issues
2
(2)
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Knowledge
/
Python2-Example100
/
Exercise014.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
30 lines (29 loc) · 1.91 KB
master
Breadcrumbs
Knowledge
/
Python2-Example100
/
Exercise014.py
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
30 lines (29 loc) · 1.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
#程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成:
#(1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。
#(2)如果n<>k,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数你n,重复执行第一步。
#(3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。
#输出的形式更加多样,可以使用 str.format() 函数来格式化输出值
# isinstance() 方法的语法:isinstance(object, classinfo),object -实例对象。classinfo -可以是直接或间接类
# 名、基本类型或者有它们组成的元组,对象的类型与参数二的类型(classinfo)相同则返回 True,否则返回 False。
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
] :
# 循环保证递归,index是另一个因子
for
index
in
xrange
(
2
,
n
+
1
) :
#xrange() 函数用法与 range 完全相同,所不同的是生
# 成的不是一个数组,而是一个生成器。
if
n
%
index
==
0
:
n
/=
index
# n 等于 n/index
if
n
==
1
:
# n=1直接输出,否则继续执行循环
print
index
else
:
# index 一定是素数
print
'{} *'
.
format
(
index
),
break
reduceNum
(
90
)
reduceNum
(
100
)
You can’t perform that action at this time.