n_tools.py

Created by cent20

Created on November 02, 2020

1.45 KB


def div1_p(n): # Version 1, avec une boucle for
    for i in range(1, n+1, 1):
        if n % i == 0:
            print(i, "est un diviseur de", n)

def div1(n): # Version 1, avec une boucle for
    liste = []
    for i in range(1, n+1, 1):
        if n % i == 0:
            liste.append(i)
    return liste
    
def div1_n(n): # Version 1, avec une boucle for
    liste = []
    for i in range(1, n+1, 1):
        if n % i == 0:
            liste.append(i)
            liste.append(-i)
    liste.sort()
    return liste


def div2_p(n): # Version 2, avec une boucle while
    i = n
    while i>0:
        if n % i == 0:
            print(i, "est un diviseur de", n)
        i = i - 1

def parfait(n): # Version 1, avec une boucle for
    for m in range(1,n+1):
      liste = []
      for i in range(1, m, 1):
          if m % i == 0:
              liste.append(i)
      if sum(liste) == m:
        print(m,"est un nombre parfait")
      
            

def isprime(n):

    prime = True

    for i in range(2, n, 1):

        if n % i == 0:

            print(n, "n'est pas un nombre premier")

            prime = False

            break

    if prime:

        print(n, "est un nombre premier")



def prime(n):

    prime = True

    for i in range(2, n, 1):

        if n % i == 0:

            prime = False

            break

    if prime:

        print(n, "est un nombre premier")





def findprime(a, b):

    for n in range(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:

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.