Advertisement
programusy

pythonj dziedziczenie

Feb 2nd, 2023
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import math;
  2.  
  3. class Punkt:
  4. def __init__(self,x=None,y=None):
  5.  
  6. self.x=int(input("podaj x")) if(x is None) else x
  7. self.y = int(input("podaj y")) if(y is None) else y
  8.  
  9.  
  10.  
  11. def wyswietl(self):
  12. print(self.x, ";", self.y, ";", self.z)
  13. def do_zera(self):
  14. c=math.sqrt(self.x*self.x+self.y*self.y)
  15. print("odelglosc od srodka wynosi:",c)
  16. def move(self,x2,y2):
  17. self.x+=x2;
  18. self.y+=y2;
  19. def move_to(self,x2,y2):
  20. self.x=x2;
  21. self.y=y2;
  22. def odleglosc_od(self,x2,y2):
  23. dx = self.x - x2
  24. dy = self.y - y2
  25. dl = math.sqrt(dx * dx + dy * dy)
  26. print("odelglosc wynosi ", dl)
  27.  
  28. class punkt3d(Punkt):
  29. def __init__(self,x=None,y=None,z=None):
  30. self.z=int(input("podaj z")) if(z is None) else z;
  31. super().__init__(x,y)
  32.  
  33.  
  34.  
  35. def main():
  36. '''p1= Punkt(1,2)
  37. print(p1.x," ", p1.y)
  38. p2= Punkt(1)
  39. print(p2.x," ", p2.y)'''
  40.  
  41. p3=punkt3d();
  42. print(p3.x, " ", p3.y, " ", p3.z)
  43. p4 = punkt3d(1);
  44. print(p4.x, " ", p4.y, " ", p4.z)
  45. p5 = punkt3d(1,2);
  46. print(p5.x, " ", p5.y, " ", p5.z)
  47. p6 = punkt3d(1,2,3);
  48. print(p6.x, " ", p6.y, " ", p6.z)
  49.  
  50.  
  51.  
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement