Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hello World program in Python
- # class definition
- class Figure:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- # Override
- def __str__(self):
- return 'x = ' + str(self.x) + ', y = ' + str(self.y) + '.'
- def move(self, x, y):
- if self.verify(x, y):
- self.x = x
- self.y = y
- def checkBorders(self, x, y):
- if x > 8 or x < 1 or y > 8 or y < 1:
- return 0
- return 1
- class Rook(Figure):
- def verify(self, x, y):
- return (self.checkBorders(x, y) and self.x == x) or (self.checkBorders(x, y) and self.y == y)
- e = Rook(1, 1)
- print(e)
- e.move(1, 8)
- print(e)
- class Triangle:
- def __init__(self, a, b, c):
- self.a = a
- self.b = b
- self.c = c
- def area(self):
- p = (self.a + self.b + self.c) / 2
- return p * (p - self.a) * (p - self.b) * (p - self.c)
- class Prism(Triangle):
- def __init__(self, a, b, c, h):
- super().__init__(a, b, c)
- self.h = h
- def area(self):
- return 2 * super().area() + (self.a + self.b + self.c) * self.h
- p = Prism(3, 4, 5, 6)
- print(p.area())
- t = Triangle(3, 4, 5)
- print(t.area())
- # function should be defined before its usage
- def GCD(a, b):
- while a != b:
- if a > b:
- a = a - b
- else:
- b = b - a
- return a
- print (GCD (125, 75))
- # object definition (json like)
- b = {
- 'fname': 'Vakhtangi',
- 'lname': 'Laluashvili',
- 'age': 22
- }
- b['weight'] = 58 # add dinamically
- for c in b:
- print (c, ": ", b[c])
- a = [2, 3, 5, 7, 11]
- a = a + [13, 17, 19, 23]
- for c in a:
- print (c)
Advertisement
Add Comment
Please, Sign In to add comment