Informatique

Question

Qui peut m'aider à faire ces exercices ? (Programmation "python" et "algorithme")
svp☺️❤️❤️❤️​
Qui peut m'aider à faire ces exercices ? (Programmation python et algorithme) svp☺️❤️❤️❤️​

1 Réponse

  • Réponse :

    def estUnNombrePremier(n):

       nbrPremier=0

       if n > 1:

           for i in range(2, int(n/2)+1):

               if (n % i) == 0:

                   break

           else:

               nbrPremier=1

               

       return nbrPremier

       

    def factorielle(n):

       fact=1

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

           fact = fact * i

       return fact

       

    def supprimeLesEspacesSuperfluts(chaine)    :

       return " ".join(chaine.split())

    uneChaine=" Je teste    cet    exemple   "

    print("Ma nouvelle chaine :", supprimeLesEspacesSuperfluts(uneChaine) )

    uneChaine="            Autre test              "

    print("Ma nouvelle chaine :", supprimeLesEspacesSuperfluts(uneChaine) )

    for x in range(1,50):

       print(x," est premier ?", estUnNombrePremier(x) )

       print("Factorielle de ",x," est ", factorielle(x) )

    Bon courage