pgcd.py

Created by alex-juge84

Created on March 21, 2022

616 Bytes


# Script PGCD
def pgcd(a : int, b : int):
  #---------Sécurités----------
  #Vérifier l'ensemble
  if type(a) != int or type(b) != int:
    return ValueError("Entiers attendus")
  
  #gérer les valeurs négatives
  a, b = abs(a), abs(b)
    
  #Eviter le cas pgcd(0,0)
  if (a == 0 and b == 0):
    return 0
    
  #Rectifier l'ordre 
  if b > a:
    a, b = b, a
  
  #Eviter la division par 0
  if b == 0:
    return a
  #--------------------
  
  while a % b != 0:
    print("{0} = {1} * {2} + {3}".format(a,b,a//b,a%b))
    a,b = b, a%b
  return b
    
    
print(pgcd(65,91))

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.