From 1f7ff179fa276a79c6a525103835ec63d5cf4be4 Mon Sep 17 00:00:00 2001 From: s45163 Date: Sat, 16 Dec 2017 11:02:48 +0100 Subject: [PATCH] p --- labs03/Podstawy 2.ipynb | 8 +++---- labs04/task02.py | 42 +++++++++++++++++++++++++++++++++++-- labs04/task03.py | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/labs03/Podstawy 2.ipynb b/labs03/Podstawy 2.ipynb index adf5795..7a591c4 100644 --- a/labs03/Podstawy 2.ipynb +++ b/labs03/Podstawy 2.ipynb @@ -232,13 +232,13 @@ { "ename": "TypeError", "evalue": "unhashable type: 'list'", - "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'" - ] + ], + "output_type": "error" } ], "source": [ @@ -398,13 +398,13 @@ { "ename": "ValueError", "evalue": "I/O operation on closed file.", - "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mlinia\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreadlines\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlinia\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: I/O operation on closed file." - ] + ], + "output_type": "error" } ], "source": [ diff --git a/labs04/task02.py b/labs04/task02.py index 162922e..a4fb8bd 100644 --- a/labs04/task02.py +++ b/labs04/task02.py @@ -1,11 +1,49 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +from random import randint + + class Employee: - def __init__(self, imie, nazwisko, id): + + def __init__(self, imie, nazwisko): self.imie = imie self.nazwisko = nazwisko - self.id = id + self.id = randint(0, 1000) # pole nie jest statyczne, nie rozumiem, dlaczego milo by byc + def get_id(self): + return self.id + +class Recruiter(Employee): + + def __init__(self, imie, nazwisko): + super(Recruiter,self).__init__(imie, nazwisko) + self.recruited = [] + def recruit(self, employee): + if isinstance(employee, Employee): + self.recruited.append(employee.get_id()) + + +class Programmer(Employee): + + def __init__(self, imie, nazwisko, recruiter): + super(Programmer, self).__init__(imie, nazwisko) + if isinstance(recruiter, Recruiter): + self.recruiter = recruiter.get_id() + + +if __name__ == '__main__': + employee = Employee("Agnieszka", "Wisniewska") + print(employee.get_id()) + + recruiter = Recruiter("Krzysztof", "Wisniewski") + recruiter.recruit(employee) + print(recruiter.get_id()) + print(recruiter.recruited) + + programmer = Programmer("Ksawery", "Wisniewski", recruiter) + print(programmer.recruiter) \ No newline at end of file diff --git a/labs04/task03.py b/labs04/task03.py index 88741a4..825b308 100644 --- a/labs04/task03.py +++ b/labs04/task03.py @@ -1,3 +1,49 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- +class Point: + + def __init__(self, coords): + if is_numeric(coords): + self.coords = coords + print(self.coords) + + def to_string(self): + print("coords:") + print(self.coords) + + def __len__(self): + return len(self.coords) + + def __str__(self): + return "coords: [" + ','.join([str(c) for c in self.coords]) + "]" + +class DimensionError(Exception): + def __init__(self, message): + super(DimensionError, self).__init__(message) + + +def add(point1, point2): + if len(point1.coords) != len(point2.coords) or len(point1.coords) == 0 or len(point2.coords) == 0: + raise DimensionError('Wrong dimensions!') + + newCoords = [] + for dim in zip(point1.coords, point2.coords): + newCoords.append(sum(dim)) + return Point(newCoords) + +def is_numeric(coords): + for el in coords: + if not isinstance(el, (int, float)): + return False + return True + +if __name__ == '__main__': + point1 = Point([1,2,3,4,5]) + point2 = Point([1,2,3,4,5]) + + point = add(point1, point2) + # point.to_string() + + print(len(point)) + print(point)