fonctions_utiles.py

Created by elnix90

Created on March 15, 2023

1.59 KB

Plusieurs fonctions utiles durant une interro de math… Faites moi savoir vos impressions sur discord: Elnix90#0116


from math import *
from kandinsky import *
from ion import *
print("""diviseurs(a)
PGCD(b,c)
premier(d)
facteurs_premiers(e)
PPCM(f,g)
diviseurs_communs(h,i)
divisible(j,k)""")
def diviseurs(a):
  racine_a=sqrt(a)
  racine_a+=1
  racine_a=floor(racine_a)
  racine2=str(racine_a)
  compter_racine2=len(str(racine2))
  i=1
  while i<racine_a:
    if a%i==0:
      chiffres=int(len(str(i)))
      racine2=int(racine2)
      espaces=compter_racine2-chiffres
      print(i," " * espaces,"x ", a // i)
    i+=1
def PGCD(b,c):
  b2=len(str(b))+1
  while 1:
    if b<c:
      b,c=c,b
    d=b%c
    esp1=1
    print(" ",b,"|_ ",c)
    print("-",b-b2,"|",b//c)
    print("_"*(len(str(b))+2),"|")
    print(" ",d,"\n")
    b=d
    if d==0:
      print("PGCD = ",c)
      break
def premier(a):
  comt=0
  i=1
  while i<a:
    if a%i==0:
      comt+=1
    if comt>1:
      break
    i+=1
  if comt==1:
    return True
  else:
    return False
def facteurs_premiers(nombre_choisi):
  i = 1
  j = int(len(str(nombre_choisi)))
  while i <= nombre_choisi:
    if premier(i) == True and nombre_choisi % i == 0:
      h = j - int(len(str(nombre_choisi)))
      print(" "*h,nombre_choisi,"|",i)
      nombre_choisi = nombre_choisi//i
    else:
      i += 1
def PPCM(m,n):
  i=2
  while 1:
    if divisible(m,i)==True and divisible(n,i)==True:
      print("PPCM=",i)
      break
    else:
      i+=1
def diviseurs_communs(o,p):
  i=1
  while i<o and i<p:
    if divisible(o,i)==True and divisible(p,i)==True:
      print(i)
      i+=1
    else:
      i+=1
def divisible(k,l):
  if k %l==0:
    return True
  else:
    return False

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.