python猜数字程序_Python程序找到完美的数字

python猜数字程序

Given an integer number and we have to check whether it is perfect number or not?

给定一个整数,我们必须检查它是否为完美数?

This Python program is used to find its all positive divisors excluding that number.

该Python程序用于查找除该数字外的所有正数除数。

Explanation: For Example, 28 is a perfect number since divisors of 28 are 1, 2, 4,7,14 then sum of its divisor is 1 + 2 + 4 + 7 + 14 = 28.

说明:例如,28是一个完美数字,因为28的除数是1、2、4、7、14,然后其除数之和是1 + 2 + 4 + 7 + 14 = 28。

Note: A perfect number is a positive integer that is equal to the sum of its proper positive divisors.

注意:理想数是一个正整数,等于其适当的正因数之和。

Python代码找到完美的数字 (Python code to find perfect number)

if __name__ == "__main__" :

    # initialisation 
    i = 2;sum = 1;

    # take input from user and typecast into integer
    n = int(input("Enter a number: "))

    # iterating till n//2 value
    while(i <= n//2 ) :

        # if proper divisor then add it.
        if (n % i == 0) :

            sum += i

        i += 1

    # check sum equal to n or not
    if sum == n :
        print(n,"is a perfect number")

    else :
        print(n,"is not a perfect number")
       

Output

输出量

First run:
Enter a number: 28
28 is a perfect number

Second run:
Enter a number: 14
14 is not a perfect number


翻译自: https://www.includehelp.com/python/program-to-find-perfect-number.aspx

python猜数字程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值