-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added Python Program to Check Perfect Number #2244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,14 +1,15 @@ | ||||||
""" | ||||||
== Perfect Number == | ||||||
In number theory, a perfect number is a | ||||||
positive integer that is equal to the sum | ||||||
of its positive divisors, excluding the | ||||||
number itself. | ||||||
>>> For 6 ==> divisors[1, 2, 3, 6] | ||||||
Excluding 6 sum(divisors) = 1 + 2 + 3 = 6 | ||||||
So, 6 is a Perfect Number | ||||||
Other examples of Perfect Numbers: 28, 486, ... | ||||||
== Perfect Number == | ||||||
In number theory, a perfect number is a positive integer | ||||||
that is equal to the sum of its positive divisors, excluding | ||||||
the number itself. | ||||||
For 6 ==> divisors[1, 2, 3, 6] | ||||||
Excluding 6 sum(divisors) = 1 + 2 + 3 = 6 | ||||||
So, 6 is a Perfect Number | ||||||
|
||||||
Other examples of Perfect Numbers: 28, 486, ... | ||||||
|
||||||
https://en.wikipedia.org/wiki/Perfect_number | ||||||
""" | ||||||
|
||||||
|
||||||
|
@@ -21,8 +22,17 @@ def perfect(number: int) -> bool: | |||||
A number at most can be divisible | ||||||
by the half of the number except | ||||||
the number itself | ||||||
>>> 6 at most can be divisible by 3 | ||||||
except 6 itself | ||||||
6 at most can be divisible by 3 | ||||||
except 6 itself | ||||||
""" | ||||||
|
||||||
""" | ||||||
>>> perfect(27) | ||||||
False | ||||||
>>> perfect(28) | ||||||
True | ||||||
>>> perfect(29) | ||||||
False | ||||||
""" | ||||||
|
||||||
if (number % i) == 0: | ||||||
|
@@ -37,8 +47,4 @@ def perfect(number: int) -> bool: | |||||
if __name__ == "__main__": | ||||||
print("Program to check whether a number is a Perfect number or not.......") | ||||||
number = int(input("Enter number: ")) | ||||||
check = perfect(number) | ||||||
if check: | ||||||
print("{} is a Perfect Number.".format(number)) | ||||||
else: | ||||||
print("{} is not a Perfect Number.".format(number)) | ||||||
print(f"{number} is {'' if perfect(number) else 'not'} a Perfect Number.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then it is taking two spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check again.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doctests must be in the (first) docstring of the function.