Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Last active September 24, 2017 02:26
Show Gist options
  • Save HorlogeSkynet/58a4e73f211a3939ec849db8915d193f to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/58a4e73f211a3939ec849db8915d193f to your computer and use it in GitHub Desktop.
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment