avkLab

Perfect Numbers

Aug 29th, 2022 (edited)
1,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | Science | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 29 août 2022
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. Un nombre parfait est un entier naturel égal à la somme de ses diviseurs stricts.
  11. 6 = 1+2+3
  12. """
  13. # ---------------------------------------------------------------------------
  14.  
  15.  
  16. nb_min = int(input("Commencer la recherche à : "))
  17. nb_max = int(input("Terminer la recherche à : "))
  18.  
  19. print()
  20. print("Les nombres parfaits de",nb_min,"à",nb_max,"sont : ")
  21.  
  22. for nb in range(nb_min, nb_max-1):
  23.     somme = 0
  24.     div = ""
  25.     for i in range(1, nb - 1):
  26.         if(nb % i == 0):
  27.             somme = somme + i
  28.             div = div + str(i) + " + " #liste des diviseurs
  29.  
  30.     if(somme == nb):
  31.         div = div[:-3] # Enlever le dernier " + "
  32.         print(str(nb)+" = "+div)
  33.        
  34. print("=== Recherche terminée ===")
  35.  
Tags: math numbers
Advertisement
Add Comment
Please, Sign In to add comment