forked from tdwojak/Python2017
Zadanie domowe labs04
This commit is contained in:
parent
57a0325708
commit
dc99f2323d
@ -1,3 +1,11 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
def is_numeric(x):
|
||||||
|
if all(isinstance(i, (int, float)) for i in x):
|
||||||
|
print 'All elements in the list are integers or floats'
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print 'NOT all elements in the list are integers or floats'
|
||||||
|
return False
|
||||||
|
@ -1,3 +1,33 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import time
|
||||||
|
|
||||||
|
class Employee:
|
||||||
|
id = int(time.time())
|
||||||
|
|
||||||
|
def __init__(self, name, surname):
|
||||||
|
self.name = name
|
||||||
|
self.surname = surname
|
||||||
|
|
||||||
|
def get_id(self):
|
||||||
|
return self.id
|
||||||
|
|
||||||
|
# Check the first class
|
||||||
|
x = Employee('Mateusz', 'Kowalski')
|
||||||
|
print x.get_id()
|
||||||
|
|
||||||
|
# Second class
|
||||||
|
class Recruiter(Employee):
|
||||||
|
recruited = []
|
||||||
|
def recruit(self):
|
||||||
|
self.recruited.append(self.get_id())
|
||||||
|
|
||||||
|
# Check the second class
|
||||||
|
y = Recruiter('Mateusz', 'Kowalski')
|
||||||
|
y.recruit()
|
||||||
|
print y.recruited
|
||||||
|
|
||||||
|
# Third class
|
||||||
|
class Programmer(Recruiter):
|
||||||
|
def recruiter(self):
|
||||||
|
self.recruiter = self.get_id()
|
||||||
|
@ -1,3 +1,46 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import task01
|
||||||
|
|
||||||
|
class DimensionError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
pointList = []
|
||||||
|
|
||||||
|
def __init__(self, coord):
|
||||||
|
if isinstance(coord, list):
|
||||||
|
if task01.is_numeric(coord):
|
||||||
|
self.coord = coord
|
||||||
|
self.x = coord[0]
|
||||||
|
self.y = coord[1]
|
||||||
|
if len(coord) == 3:
|
||||||
|
self.z = coord[2]
|
||||||
|
|
||||||
|
self.pointList.append(self.coord)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print 'NOT all elements in the list are integers or floats'
|
||||||
|
else:
|
||||||
|
raise DimensionError('The argument must be a list')
|
||||||
|
|
||||||
|
def add(self, point1, point2):
|
||||||
|
point3 = []
|
||||||
|
|
||||||
|
if isinstance(point1, Point) and isinstance(point2, Point):
|
||||||
|
point3.append(point1.x + point2.x)
|
||||||
|
point3.append(point1.y + point2.y)
|
||||||
|
point3.append(point1.z + point2.z)
|
||||||
|
return Point(point3)
|
||||||
|
else:
|
||||||
|
print 'Arguments must be Points'
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.coord)
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
return 'Point coordinates: x: {0} y: {1} z: {2}'.format(self.x, self.y, self.z)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
print self.to_string()
|
||||||
|
Loading…
Reference in New Issue
Block a user