SimeonTs

SUPyF2 Functions-Exercise - 07. Perfetct Number

Oct 8th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. """
  2. Functions - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1728#6
  4.  
  5. SUPyF2 Functions-Exercise - 07. Perfetct Number
  6.  
  7. Problem:
  8. Write a function that receives an integer number and returns if this number is perfect or NOT.
  9. A perfect number is a positive integer that is equal to the sum of its proper positive divisors.
  10. That is the sum of its positive divisors excluding the number itself (also known as its aliquot sum).
  11.  
  12. Examples:
  13. Input:      Output:                      Comments:
  14. 6           We have a perfect number!    1 + 2 + 3
  15. 28          We have a perfect number!    1 + 2 + 4 + 7 + 14
  16. 1236498     It's not so perfect.
  17. Hint
  18. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself) => 6 is a perfect number, because it is the sum of 1 + 2 + 3 (all of which are divided without residue).
  19. • Read about the Perfect number here: https://en.wikipedia.org/wiki/Perfect_number
  20.  
  21. """
  22.  
  23.  
  24. def perfect_number(number):
  25.     result = 0
  26.     for i in range(1, number):
  27.         if number % i == 0:
  28.             result = result + i
  29.     if result == number:
  30.         print("We have a perfect number!")
  31.     else:
  32.         print("It's not so perfect.")
  33.  
  34.  
  35. perfect_number(int(input()))
Add Comment
Please, Sign In to add comment