1
0
forked from tdwojak/Python2017
This commit is contained in:
s45163 2017-12-16 11:02:48 +01:00
parent e3ef2766de
commit 1f7ff179fa
3 changed files with 90 additions and 6 deletions

View File

@ -232,13 +232,13 @@
{ {
"ename": "TypeError", "ename": "TypeError",
"evalue": "unhashable type: 'list'", "evalue": "unhashable type: 'list'",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-25-2bd2fa17fbf5>\u001b[0m in \u001b[0;36m<module>\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;32m<ipython-input-25-2bd2fa17fbf5>\u001b[0m in \u001b[0;36m<module>\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'" "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'"
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [
@ -398,13 +398,13 @@
{ {
"ename": "ValueError", "ename": "ValueError",
"evalue": "I/O operation on closed file.", "evalue": "I/O operation on closed file.",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-47-f06513c1bbec>\u001b[0m in \u001b[0;36m<module>\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;32m<ipython-input-47-f06513c1bbec>\u001b[0m in \u001b[0;36m<module>\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." "\u001b[0;31mValueError\u001b[0m: I/O operation on closed file."
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [

View File

@ -1,11 +1,49 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from random import randint
class Employee: class Employee:
def __init__(self, imie, nazwisko, id):
def __init__(self, imie, nazwisko):
self.imie = imie self.imie = imie
self.nazwisko = nazwisko 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): 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)

View File

@ -1,3 +1,49 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- 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)