Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# HorlogeSkynet/primeNumbersInterval.py

Last active Sep 24, 2017
A simple Python script to display prime numbers present within a given interval
 #!/usr/bin/env python3 # -*-coding:utf-8 -* from math import sqrt def premier(borne1, borne2): nombresPremiers = 0 print() if borne1 > borne2: borne1, borne2 = borne2, borne1 for dividende in range(borne1, borne2 + 1, 1): for diviseur in range(1, int(sqrt(dividende)) + 1, 1): if dividende % diviseur == 0 and diviseur != 1: break else: if diviseur == int(sqrt(dividende)) and dividende != 1: print("\t{}".format(dividende)) nombresPremiers += 1 return nombresPremiers if __name__ == '__main__': borne1 = abs(int(input("Entrez la première valeur d'un intervalle: "))) borne2 = abs(int(input("Entrez la seconde valeur d'un intervalle: "))) print("\n\nIl y a {} nombre(s) premier(s) entre {} et {}.\n".format(premier(borne1, borne2), borne1, borne2))
to join this conversation on GitHub. Already have an account? Sign in to comment