Advertisement
FranzVuttke

pythagoras_triplet.py

Oct 3rd, 2023 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | Source Code | 0 0
  1. # https://www.facebook.com/groups/python/posts/1508202230020336/?__cft__[0]=AZUIx1wejwuzvHy0K7k8yo56G_n5sD1TZYvAuVfJJa0R_H-2Ol2IT3geUFj2pTxiHVePz7P_C01FGoAPM_-EDWQROqrkg5clYchjSzCtiLnVzA64e3jkPZD8ABz7TXq2UV1YXCYLx9mip8iTDIGBa4-t&__tn__=%2CO%2CP-R
  2. # Trójki Pitagorasa
  3.  
  4. import math
  5.  
  6. for x in range(2, 100):
  7.     #print(type(sqrt(x + x+1)))    
  8.     #if (x + x+1 == sqrt(x + x+1)**2):
  9.  
  10.     #if (isinstance(sqrt(x + x+1), int)): # nie działą
  11.  
  12.     # alternatywa 1.
  13.     # funkcja modf
  14.     # https://www.educative.io/answers/how-to-extract-the-fractional-part-of-a-float-number-in-python
  15.     # if (modf(sqrt(x + x+1))[0] == 0):
  16.    
  17.     # alternatywa 2.
  18.     # przechodzi gdy część dziesiętna floata jest równa zeru po konwersji na str "0"
  19.     # if str(sqrt(x + x+1)).split(".")[1] == "0":
  20.  
  21.     # alternatywa 3.
  22.     # od liczby rzeczywistej (float) odjąć całkowitą po konwrersji (int)
  23.     if (math.sqrt(x + x+1) - int(math.sqrt(x + x+1))) == 0:
  24.         print(x, x+1, x + x+1)
  25.     #print(sqrt(x + x+1) - int(sqrt(x + x+1)))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement