avkLab

Triplets pythagoriciens

Dec 22nd, 2022 (edited)
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 22/12/2022
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. Un triplet pythagoricien est un triplet (a, b, c) d'entiers naturels non nuls
  11. vérifiant la relation de Pythagore : a**2 + b**2 = c**2.
  12. Exemple : [3,4,5]
  13. """
  14. # ---------------------------------------------------------------------------
  15.  
  16. import math
  17.  
  18. def triangles_pyth(n):
  19.     for a in range(n):
  20.         for b in range(1, a):
  21.             c = math.sqrt( a * a + b * b)
  22.             if c % 1 == 0:
  23.                 c=int(c)
  24.                 print("["+str(a)+","+str(b)+","+str(c)+"] : "+str(a)+"^2 + " + str(b)+"^2 = "+ str(c)+"^2")
  25.  
  26. max = int(input("Soit le coté donné d'un triangle, quelle est sa valeur maximale ? "))
  27. print("Les triangles pythagoriciens recherchés sont : ")
  28. triangles_pyth(max)
  29.  
  30.  
Tags: math numbers
Advertisement
Add Comment
Please, Sign In to add comment