Solution Exercice 15 tester si un nombre est premier en Python

Exercice 15

Ecrire un programme en langage Python qui demande à l'utilisateur de saisir un nombre entier n et de lui afficher si ce nombre est premier ou non.

Solution




 

Younes Derfoufi
CRMEF OUJDA

4 thoughts on “Solution Exercice 15 tester si un nombre est premier en Python

  1. def est_premier(nombre):
    i = 2
    premier = False
    while i < nombre and nombre % i != 0 :
    i += 1
    if i == nombre:
    premier = True
    return premier

    nombre = int(input("Entrez un nombre entier : "))
    if est_premier(nombre) == True:
    print("Le nombre est premier")
    else:
    print("Nombre pas premier")

Leave a Reply to TP Python: Exercices corrigés d’algorithmique Python – Les bases | Cours Python Très Facile Cancel reply

Your email address will not be published. Required fields are marked *