RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Python程序:寻找整数所有除数

创新互联Python教程:

创新互联是专业的怀化网站建设公司,怀化接单;提供成都网站设计、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行怀化网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

编写一个 Python 程序,使用 for 循环查找整数或数字的所有除数。在这个 Python 示例中,for 循环从 1 迭代到给定的数字,并检查每个数字是否可以被数字完全整除。如果为真,则将该数作为除数打印出来。

num = int(input("Please enter any integer to find divisors = "))

print("The Divisors of the Number = ")

for i in range(1, num + 1):
    if num % i == 0:
        print(i)

Python 程序使用 while 循环查找整数的所有除数。

num = int(input("Please enter any integer to find divisors = "))

print("The Divisors of the Number = ")

i = 1

while(i <= num):
    if num % i == 0:
        print(i)
    i = i + 1
Please enter any integer to find divisors = 100
The Divisors of the Number = 
1
2
4
5
10
20
25
50
100

在这个 Python 示例中,我们创建了一个 find 除数函数,它将查找并返回给定数字的所有除数。

def findDivisors(num):
    for i in range(1, num + 1):
        if num % i == 0:
            print(i)
# End of Function

num = int(input("Please enter any integer to find divisors = "))

print("The Divisors of the Number = ")
findDivisors(num)
Please enter any integer to find divisors = 500
The Divisors of the Number = 
1
2
4
5
10
20
25
50
100
125
250
500

文章题目:Python程序:寻找整数所有除数
网站地址:http://jxjierui.cn/article/dhodjpj.html