Advertisement
Razorspined

Untitled

Oct 17th, 2022
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Oct 17 14:43:18 2022
  4.  
  5. @author: Йордан Цанков
  6. """
  7.  
  8. '''
  9. list       -  []
  10. tuple      -  ()
  11. set        -  {} {1,2,5,6,8}
  12. dictionary -  {} {"ime": "ivan", "ime": "pesho"}
  13. '''
  14.  
  15. import math
  16.  
  17. #print({"drugo_ime": "ivan", "ime": "ivan"})
  18.  
  19. #parameter packing
  20. #variable amount of parameters
  21. def sayHello(predstavka, *name):
  22.     print(name)
  23.     for n in name:
  24.         print("hello", n)
  25.        
  26. def sum(*numbers: int):
  27.     total = 0
  28.     for number in numbers:
  29.         total += number
  30.        
  31.     return total
  32.    
  33.        
  34.        
  35. def sayHelloAgain(x, **params):
  36.     print(params)
  37.     for (key,value) in params.items():
  38.         print(key, value)
  39.        
  40. def otherFn(name="", age=0):
  41.     pass
  42.    
  43.  
  44. print(sum(5,5,1,54,213,6655))
  45. sayHello("ivan", "pesho", "gosho")
  46. sayHelloAgain(10, age=35, name="pesho", obicha_kotki=True, age_again=22)
  47.    
  48. otherFn(age=35,name="ivan")
  49.  
  50.  
  51. class Point:
  52.    
  53.     # дали променливите са тук
  54.     def __init__(self, x, y):
  55.         # или са тук
  56.         self.x = x
  57.         self.y = y
  58.        
  59.     def distanceTo(self, otherPoint):
  60.         return math.sqrt((self.x - otherPoint.x) ** 2 + (self.y - otherPoint.y) ** 2)
  61.    
  62. # клас за обект триъгълник - той се дефинира от три точки
  63. # да можем да сметнем обиколката на този триъгълник
  64.  
  65. class Triangle:
  66.    
  67.    
  68.     def __init__(self, a, b, c):
  69.         self.a = a
  70.         self.b = b
  71.         self.c = c
  72.        
  73.        
  74.     def perimeter(self):
  75.         side_a = self.a.distanceTo(self.b)
  76.         side_b = self.b.distanceTo(self.c)
  77.         side_c = self.a.distanceTo(self.c)
  78.        
  79.         return side_a + side_b + side_c
  80.    
  81.  
  82. pointA = Point(0, 0)
  83. pointB = Point(10,10)
  84. triangle1 = Triangle(Point(0, 0), pointB, Point(5,3))
  85. print(triangle1.hello())
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement