pythagore.py

Created by 1epauletteshark

Created on January 04, 2024

1.99 KB


from math import sqrt

def hypothenuse(t,a,b,u="cm"):
  print("-"*43)
  print("Le triangle {} est rectangle en {} donc,".format(t,t[1]))
  print("dapres le theoreme de Pythagore on a:")
  print("-"*43)
  print("{}^2 = {}^2 + {}^2".format(t[0]+t[2],t[:2],t[1:]))
  print("{} = {}{} et {} = {}{}".format(t[:2],a,u,t[1:],b,u))
  print("-"*43)
  print("{}^2 = {}^2 + {}^2".format(t[0]+t[2],a,b))
  print("{}^2 = {} + {}".format(t[0]+t[2],a**2,b**2))
  print("{}^2 = {}".format(t[0]+t[2],a**2+b**2))
  print("{} = sqrt({})".format(t[0]+t[2],a**2+b**2))
  print("soit {} = {}{}".format(t[0]+t[2],sqrt(a**2+b**2),u))
  print("-"*43)

def longueur(t,h,a,u="cm"):
  print("-"*43)
  print("Le triangle {} est rectangle en {} donc,".format(t,t[1]))
  print("dapres le theoreme de Pythagore on a:")
  print("-"*43)
  print("{}^2 = {}^2 - {}^2".format(t[1:],t[0]+t[2],t[:2]))
  print("{} = {}{} et {} = {}{}".format(t[0]+t[2],h,u,t[:2],a,u))
  print("-"*43)
  print("{}^2 = {}^2 - {}^2".format(t[1:],h,a))
  print("{}^2 = {} - {}".format(t[1:],h**2,a**2))
  print("{}^2 = {}".format(t[1:],h**2-a**2))
  print("{} = sqrt({})".format(t[1:],h**2-a**2))
  print("soit {} = {}{}".format(t[1:],sqrt(h**2-a**2),u))
  print("-"*43)

def reciproque(t,h,a,b,u="cm"):
  print("-"*43)
  print("Dune part {} = {}^2 = {}".format(t[0]+t[2],h,h**2))
  print("Dautre part {} + {} = {}^2 + {}^2 = {}".format(t[:2],t[1:],a,b,a**2+b**2))
  print("-"*43)
  if h**2==a**2+b**2:
    print("donc dapres la reciproque du theoreme")
    print("de Pythagore, le triangle {} est".format(t))
    print("rectangle en {}".format(t[1]))
  else:
    print("donc dapres la contraposee du theoreme")
    print("de Pythagore, le triangle {} nest".format(t))
    print("pas rectangle".format(t[1]))

print("-"*43)
print("hypothenuse(t,u,a,b)")
print("longueur(t,u,h,a)")
print("reciproque(t,u,h,a,b)")
print("-"*43)
print('t = nom du triangle #"ABC"')
print("h = hypothenuse #5")
print('u = unite #"cm"')
print("a = longueur 1")
print("b = longueur 2")
print("-"*43)