Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Mon Oct 17 14:43:18 2022
- @author: Йордан Цанков
- """
- '''
- list - []
- tuple - ()
- set - {} {1,2,5,6,8}
- dictionary - {} {"ime": "ivan", "ime": "pesho"}
- '''
- import math
- #print({"drugo_ime": "ivan", "ime": "ivan"})
- #parameter packing
- #variable amount of parameters
- def sayHello(predstavka, *name):
- print(name)
- for n in name:
- print("hello", n)
- def sum(*numbers: int):
- total = 0
- for number in numbers:
- total += number
- return total
- def sayHelloAgain(x, **params):
- print(params)
- for (key,value) in params.items():
- print(key, value)
- def otherFn(name="", age=0):
- pass
- print(sum(5,5,1,54,213,6655))
- sayHello("ivan", "pesho", "gosho")
- sayHelloAgain(10, age=35, name="pesho", obicha_kotki=True, age_again=22)
- otherFn(age=35,name="ivan")
- class Point:
- # дали променливите са тук
- def __init__(self, x, y):
- # или са тук
- self.x = x
- self.y = y
- def distanceTo(self, otherPoint):
- return math.sqrt((self.x - otherPoint.x) ** 2 + (self.y - otherPoint.y) ** 2)
- # клас за обект триъгълник - той се дефинира от три точки
- # да можем да сметнем обиколката на този триъгълник
- class Triangle:
- def __init__(self, a, b, c):
- self.a = a
- self.b = b
- self.c = c
- def perimeter(self):
- side_a = self.a.distanceTo(self.b)
- side_b = self.b.distanceTo(self.c)
- side_c = self.a.distanceTo(self.c)
- return side_a + side_b + side_c
- pointA = Point(0, 0)
- pointB = Point(10,10)
- triangle1 = Triangle(Point(0, 0), pointB, Point(5,3))
- print(triangle1.hello())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement