primalite.py

Created by florian-allard

Created on June 06, 2018

301 Bytes

Affiche, pour chaque nombre entier compris entre les deux nombres entiers donnés en entrée, s’il est premier. Et s’il n’est pas premier, affiche son nombre de diviseurs.


from math import *
def primalite(a,b):  
  for i in range(a,b):
    nbdiv=2
    for j in range(2,int(sqrt(i))+1):
      if i%j==0:
        nbdiv+=2
    if nbdiv==2:
      print(i,"est premier")
    else:
      if i%sqrt(i)==0:
        nbdiv-=1
      print(i,"admet",nbdiv,"diviseurs")

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.