defdiv1_p(n):# Version 1, avec une boucle for
foriinrange(1,n+1,1):ifn%i==0:print(i,"est un diviseur de",n)defdiv1(n):# Version 1, avec une boucle for
liste=[]foriinrange(1,n+1,1):ifn%i==0:liste.append(i)returnlistedefdiv1_n(n):# Version 1, avec une boucle for
liste=[]foriinrange(1,n+1,1):ifn%i==0:liste.append(i)liste.append(-i)liste.sort()returnlistedefdiv2_p(n):# Version 2, avec une boucle while
i=nwhilei>0:ifn%i==0:print(i,"est un diviseur de",n)i=i-1defparfait(n):# Version 1, avec une boucle for
forminrange(1,n+1):liste=[]foriinrange(1,m,1):ifm%i==0:liste.append(i)ifsum(liste)==m:print(m,"est un nombre parfait")defisprime(n):prime=Trueforiinrange(2,n,1):ifn%i==0:print(n,"n'est pas un nombre premier")prime=Falsebreakifprime:print(n,"est un nombre premier")defprime(n):prime=Trueforiinrange(2,n,1):ifn%i==0:prime=Falsebreakifprime:print(n,"est un nombre premier")deffindprime(a,b):forninrange(a,b+1):prime(n)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.