Compare commits

...

34 Commits

Author SHA1 Message Date
Przemysław Kaczmarek 2cc5813593 resolved 2018-01-12 18:30:33 +01:00
Przemysław Kaczmarek 2203a269d5 resolved 2018-01-12 18:03:53 +01:00
Przemysław Kaczmarek 83f27fc1a9 resolved 2018-01-12 17:54:03 +01:00
Przemysław Kaczmarek b987dc0cc0 resolved 2018-01-12 17:37:46 +01:00
Przemysław Kaczmarek ad873598bb resolved 2018-01-12 16:55:14 +01:00
Przemysław Kaczmarek dce7564e23 resolved 2018-01-11 21:14:43 +01:00
Przemysław Kaczmarek c1259d2d03 resolved 2018-01-11 19:59:37 +01:00
Przemysław Kaczmarek aac65580c0 resolved 2018-01-11 19:48:24 +01:00
Przemysław Kaczmarek 0ec6182dde resolved 2018-01-11 19:23:47 +01:00
Przemysław Kaczmarek 8343e028b0 resolved 2018-01-11 18:28:31 +01:00
Przemysław Kaczmarek 91ba66165d resolved 2018-01-11 18:20:25 +01:00
Przemysław Kaczmarek e0beb9d336 resolved 2017-12-14 20:31:14 +01:00
Przemysław Kaczmarek aed06ae658 in progress 2017-12-14 20:02:17 +01:00
Przemysław Kaczmarek 8d38a7ddb4 in progress 2017-12-14 18:44:10 +01:00
Przemysław Kaczmarek cf0d9945b9 Resolved 2017-12-14 18:09:05 +01:00
s45151 a37ec78f22 resolve2 2017-12-03 15:36:13 +01:00
s45151 66223f51c8 resolve2 2017-12-03 15:22:45 +01:00
s45151 f841b1e161 resolve2 2017-12-03 13:44:41 +01:00
s45151 c7c39c177c resolve 2017-12-03 13:42:49 +01:00
s45151 3be168820c Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017 2017-12-03 13:21:55 +01:00
s45151 72bb0119a7 resolve 2017-12-02 15:33:12 +01:00
s45151 30a30cb566 resolve 2017-12-02 15:32:00 +01:00
Przemysław Kaczmarek ccd03ece50 Resolved 2017-11-28 19:47:40 +01:00
Przemysław Kaczmarek 4e8b83e4f2 Resolved 2017-11-28 19:46:52 +01:00
Przemysław Kaczmarek d9564f3b1a Resolved 2017-11-28 19:38:07 +01:00
Przemysław Kaczmarek 4f6c4e9062 Resolved 2017-11-28 19:12:03 +01:00
Przemysław Kaczmarek 02728e80a3 Resolved 2017-11-28 18:50:00 +01:00
Przemysław Kaczmarek 9115943f9c Resolved 2017-11-28 18:44:32 +01:00
Przemysław Kaczmarek 2438b456f4 Resolved 2017-11-28 18:42:38 +01:00
Przemysław Kaczmarek d2dfa3bfce Resolved 2017-11-28 18:38:06 +01:00
Przemysław Kaczmarek 92127f821f Resolved 2017-11-28 18:37:51 +01:00
Przemysław Kaczmarek b195295736 Resolved 2017-11-28 18:31:17 +01:00
Przemysław Kaczmarek 87b7b6d675 Resolved 2017-11-28 18:27:00 +01:00
s45151 76f3b5ba55 First commit 2017-11-19 15:43:25 +01:00
40 changed files with 7257 additions and 213 deletions

11
.idea/Python2017.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.4.3 (C:\Python34\python.exe)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Python2017.iml" filepath="$PROJECT_DIR$/.idea/Python2017.iml" />
</modules>
</component>
</project>

View File

@ -6,8 +6,14 @@ Zad 2. Napisz funkcję even_elements zwracającą listę,
która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
pass
newlist=[]
for element in lista:
if lista.index(element)%2==0:
newlist.append(element)
return newlist
def tests(f):

View File

@ -5,8 +5,11 @@
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
"""
def days_in_year(days):
pass
def days_in_year(year):
if (year%4 == 0 and year%100 != 0) or year%400==0:
return 366
else:
return 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,8 +13,14 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
pass
text_words=text.split()
oov_list=[]
for word in text_words:
if word in vocab:
pass
else:
oov_list.append(word)
return oov_list
def tests(f):
@ -30,3 +36,5 @@ def tests(f):
if __name__ == "__main__":
print(tests(oov))

View File

@ -7,7 +7,13 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
def sum_from_one_to_n(n):
pass
results=0
if n<1:
return results
else:
for i in range(n+1):
results+=i
return results
def tests(f):

View File

@ -8,9 +8,14 @@ dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako
trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
import math
def euclidean_distance(x, y):
pass
value=0
for i in range(3):
value+=math.pow((y[i]-x[i]),2)
return math.sqrt(value)
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,14 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
pass
string="N"
if n<5:
return "It's not a Big 'No!'"
else:
for i in range(n):
string+="O"
return string+"!"
def tests(f):
inputs = [[5], [6], [2]]

View File

@ -6,7 +6,10 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
def char_sum(text):
pass
results=0
for letter in text:
results+=ord(letter)
return results
def tests(f):
inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n.
"""
def sum_div35(n):
pass
results=0
for i in range(n):
if i%3==0 or i%5==0:
results+=i
return results
def tests(f):
inputs = [[10], [100], [3845]]
@ -21,4 +25,3 @@ def tests(f):
if __name__ == "__main__":
print(tests(sum_div35))

View File

@ -9,7 +9,20 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
pass
new_text=[]
for i in range(len(text)):
if text[i] == 'e':
new_text.append('3')
elif text[i] == 'l':
new_text.append('1')
elif text[i] == 'o':
new_text.append('0')
elif text[i] == 't':
new_text.append('7')
else:
new_text.append(text[i])
return ("".join(new_text))
def tests(f):
@ -24,3 +37,5 @@ def tests(f):
if __name__ == "__main__":
print(tests(leet_speak))

View File

@ -9,8 +9,13 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
pokemon_text=[]
for i in range(len(text)):
if i%2==0 and ord(text[i])>=97 and ord(text[i])<=122:
pokemon_text.append(str(chr(ord(text[i])-32)))
else:
pokemon_text.append((text[i]))
return "".join(pokemon_text)
def tests(f):
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
@ -23,4 +28,4 @@ def tests(f):
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(pokemon_speak))
print(tests(pokemon_speak))

View File

@ -8,8 +8,18 @@ uporządkowaną listę wspólnych liter z lańcuchów string1 i string2.
Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
common_letters=[]
results=[]
for letter in string1:
if letter in string2 and ord(letter)<=122 and ord(letter)>=97:
common_letters.append(ord(letter))
common_letters=set(common_letters)
print(common_letters)
for letter in common_letters:
results.append(chr(letter))
return results
def tests(f):

View File

@ -6,7 +6,7 @@ def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
return a + b
pass
def tests(f):
inputs = [(2, 3), (0, 0), (1, 1)]
@ -18,4 +18,5 @@ def tests(f):
break
return "TESTS PASSED"
print(tests(suma))
if __name__ == "__main__":
print(tests(suma))

View File

@ -49,34 +49,22 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n",
"[1, 2, 3, 1, 2, 3]\n",
"123\n"
]
}
],
"outputs": [],
"source": [
"def dwojak(x): \n",
" x *= 2\n",
" return x\n",
"def dwojak(x): x *= 2\n",
" \n",
"l = [1, 2, 3]\n",
"s = \"123\"\n",
"\n",
"dwojak(l)\n",
"dwojak(s)\n",
"print(dwojak(1))\n",
"\n",
"print(l)\n",
"print(s)"
]
@ -116,28 +104,16 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 1, 2, 3]\n",
"F: [1, 2, 3, 1, 2, 3]\n",
"[1, 2, 3]\n"
]
}
],
"outputs": [],
"source": [
"def dwojak1(x): x *= 2\n",
"def dwojak2(x): \n",
" x = x * 2\n",
" print(\"F:\", x)\n",
"def dwojak2(x): x = x * 2\n",
"\n",
"l = [1,2, 3]\n",
"dwojak1(l)\n",
@ -150,47 +126,29 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3]\n",
"[1, 2, 3, 4]\n"
]
}
],
"outputs": [],
"source": [
"l = [1, 2, 3]\n",
"e = l[:]\n",
"e = l\n",
"e.append(4)\n",
"print(l)\n",
"print(e)"
"print(l)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1], [1], [1]]\n"
]
}
],
"outputs": [],
"source": [
"e = []\n",
"f = [e for i in range(3)]\n",
@ -214,39 +172,18 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1, 'napis', [0])\n",
"3\n"
]
},
{
"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<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'"
]
}
],
"outputs": [],
"source": [
"t = (1, \"napis\", [])\n",
"t[-1].append(0)\n",
"t = (1, \"napis\", None)\n",
"elem = t[0]\n",
"print(t)\n",
"print(len(t))\n",
"print({t: None})"
"print(len(t))"
]
},
{
@ -262,29 +199,19 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"15\n",
"a == 1\n",
"b == (3, 4)\n"
]
}
],
"outputs": [],
"source": [
"def suma(*args):\n",
" return sum(args)\n",
"print(suma(1,2,3,4,5))\n",
"\n",
"def greet_me(z=None,**kwargs):\n",
"def greet_me(**kwargs):\n",
" if kwargs is not None:\n",
" for key, value in kwargs.items():\n",
" print(\"%s == %s\" %(key,value))\n",
@ -304,32 +231,16 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"97\n",
"a\n",
"98\n",
"b\n",
"99\n",
"c\n",
"100\n",
"d\n"
]
}
],
"outputs": [],
"source": [
"def alfaRange(x, y):\n",
" for i in range(ord(x), ord(y)):\n",
" print(i)\n",
" yield chr(i)\n",
"\n",
"for c in alfaRange('a', 'e'):\n",
@ -349,74 +260,40 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"W Paryżu najlepsze kasztany są na placu Pigalle\n",
"Zuzanna lubi je tylko jesienią.\n",
"\n",
">>\n"
]
}
],
"outputs": [],
"source": [
"plik = open(\"haslo.txt\", 'r')\n",
"for linia in plik.readlines():\n",
" print(linia.strip())\n",
"print(plik.read())\n",
"print(\">>\")\n",
"plik.close()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"W Paryżu najlepsze kasztany są na placu Pigalle\n",
"\n",
"Zuzanna lubi je tylko jesienią.\n",
"\n"
]
},
{
"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<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."
]
}
],
"outputs": [],
"source": [
"with open(\"haslo.txt\", 'r') as plik:\n",
" for linia in plik.readlines():\n",
" print(linia)\n",
"print(plik.read())"
"# print(plik.read())"
]
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
@ -457,22 +334,13 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"posix\n",
"Nazwa uzytkownika: tomaszd\n"
]
}
],
"outputs": [],
"source": [
"import os\n",
"print(os.name)\n",
@ -483,31 +351,13 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Counter({'o': 4, 'n': 4, 'a': 4, 'k': 3, 't': 3, 'y': 2, 'i': 2, 'c': 2, 'z': 2, 's': 1, 'p': 1, 'l': 1, 'ń': 1, 'w': 1, 'e': 1})\n"
]
},
{
"data": {
"text/plain": [
"array([[ 1., 3., 4., 5.]], dtype=float32)"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from collections import *\n",
"print(Counter(\"konstantynopolitańczykowianeczka\"))\n",
@ -544,23 +394,13 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What's your name?\n",
"Tomasz\n",
"Welcome home, Tomasz.\n"
]
}
],
"outputs": [],
"source": [
"name = input(\"What's your name?\\n\")\n",
"print(\"Welcome home, {}.\".format(name))"

32
labs03/zadanie 1.py Normal file
View File

@ -0,0 +1,32 @@
"""
**ćwiczenie 1**
Każdy obiekt w Pythonie na wbudowaną funkcję ``id()``, która zwraca liczbę, która jest unikatowa i stała dla obiektu.
Pozwala ona w prosty sposób sprawdzić, który obiekt jest *mutable*a, który *immutable*: jeżeli po wykonaniu operacji,
zwracana liczba jest stała, to oznacza, że obiekt jest *mutable*. Sprawdź zachowanie funkcji na obiektach typy:
* lista,
* napis (string),
* liczba zmiennoprzecinkowa.
"""
def f(typ):
return id(typ)
def tests():
lista=[1,2,3]
napis='1234'
float=1.42
id_table_back = [f(lista),f(napis),f(float)]
typ = ['lista','napis','liczba zmiennoprzecinkowa']
lista.append(5)
napis='1234'+'5'
float*=2
id_table_now = [f(lista), f(napis), f(float)]
for i in range(len(id_table_back)):
if id_table_back[i]==id_table_now[i]:
print(typ[i],'jest mutable')
else:
print(typ[i],'jest immutable')
tests()

25
labs03/zadanie 2.py Normal file
View File

@ -0,0 +1,25 @@
"""
**ćwiczenie 2**
Napisz generator, który będzie zwracać ``n`` kolejnych liczb ciągu Fibonacciego (``F(0)=1, F(1)=1, FN=F(N-1) + F(N-2)``).
"""
def FiboGenerator(n):
for i in range(n):
if n==0:
return 1
elif n==1:
return 1
else:
return FiboGenerator(n-1)+FiboGenerator(n-2)
"""
def tests(f):
inputs = [0,1,2,3,4,5,6,7,8]
for input in zip(inputs):
print(f(2))
if __name__ == "__main__":
print(tests(FiboGenerator))
"""
print(FiboGenerator(1))

19
labs03/zadanie 3.py Normal file
View File

@ -0,0 +1,19 @@
"""
Strona ``https://api.fixer.io/latest`` udostępnia kursy różnych walut w stosunku do euro. Napisz skrypt, który:
* pobierze zawartość JSONa. Wykorzystaj bibliotekę ``requests`` (http://docs.python-requests.org/en/master/).
* korzystając z biblioteki ``json`` przekształć go do obiketu typu JSON.
* Wyświetl wartość kursu EUR do PLN.
"""
import requests
import json
def script():
page='https://api.fixer.io/latest'
r=requests.get(page)
r.status_code
r.encoding
r.text
data_json=r.json()
print(data_json['rates'],data_json['rates'].values())
script()

View File

@ -1,3 +1,34 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
**ćwiczenie 1**
Napisz funckję ``is_numeric``, która sprawdzi, czy każdy element z przekazanej listy jest typu int lub float.
Wykorzystaj funcję ``isinstance()`` (https://docs.python.org/2/library/functions.html#isinstance).
"""
def is_numeric(n):
if isinstance(n,int):
return 'type int'
elif isinstance(n,float):
return 'type float'
elif isinstance(n,str):
return 'type string'
else:
return 'type unavailable'
def tests(f):
inputs = [1,2,5,'test',2,4.32423]
outputs = ['type int','type int','type int','type string','type int','type float']
for input, output in zip(inputs, outputs):
if f(input) != (output):
return "ERROR: {}!={}".format(f(input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(is_numeric))

View File

@ -1,3 +1,82 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
**ćwiczenie 2**
Napisz prostą hierarchię klas:
* Klasa bazowa ``Employee``, która będzie zawierać informacje o imieniu i nazwisku pracownika. Ponadto każdy pracownik
otrzyma numer ``id``, który będzie unikatowy. Wykorzystaj do tego atrybut statyczny. Napisz metodę ``get_id``, która
zwraca identyfikator pracownika.
* Klasy pochodna: ``Recruiter``, która ma dodatkową mtodę ``recruit``, która jako parament przyjmuje obiekt `
`Employee`` i zapisuje jego ``id`` w liście ``self.recruited``.
* Klasa pochodna ``Programmer``. Klasa ``Programmer`` ma przyjąć w konstruktorze podstawowe informacje (imię i nazwisko)
oraz obiekt rekturera. Ponadto stwórz atrybut ``recruiter``, który będzie przechowywać ``id`` rekrutera.
"""
class Employee():
id=0
@staticmethod
def add_id():
Employee.id+=1
return id
def __init__(self, name, surname):
Employee.add_id()
self.id = Employee.id
self.name = name
self.surname = surname
def get_id(self):
return self.id
def __repr__(self):
return '<Employee, %s, %s %s>' % (self.id,self.name,self.surname)
class Recruiter(Employee):
def __init__(self,name,surname):
super().__init__(name,surname)
self.recruited=[]
def recruite(self,Employee):
self.recruited.append(Employee.get_id())
def __repr__(self):
return '<Recruiter, %s, %s %s>' % (self.id, self.name, self.surname)
class Programmer(Employee):
def __init__(self,name,surname,Recruiter):
super().__init__(name,surname)
self.recruiter = Recruiter.get_id()
def __repr__(self):
return '<Programmer, %s, %s %s>' % (self.id, self.name, self.surname)
def TestFunction():
pracownik_przemek=Employee('Przemyslaw','Kaczmarek')
print(pracownik_przemek.name,pracownik_przemek.surname)
pracownik_michal=Employee('Michał','Kowalski')
rekruter_mariusz=Recruiter('Mariusz','Małysz')
programista_adam=Programmer('Adam','Kowalski',rekruter_mariusz)
rekruter_maciej=Recruiter('Maciej','Fisko')
rekruter_maciej.recruite(pracownik_przemek)
rekruter_maciej.recruite(rekruter_mariusz)
rekruter_mariusz.recruite(programista_adam)
rekruter_mariusz.recruite(pracownik_michal)
print('Maciej zrekrutowal: ',rekruter_maciej.recruited)
print('Mariusz zrekrutowal: ',rekruter_mariusz.recruited)
print('Adam zostal zrekrutowany przez: ',programista_adam.recruiter)
print('Liczba pracownikow: ',Employee.id)
print(pracownik_przemek)
print(pracownik_michal)
print(rekruter_mariusz)
print(programista_adam)
print(rekruter_maciej)
TestFunction()

View File

@ -1,3 +1,89 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
class DimensionError(Exception):
"""Discreapncies in dimensions. We cannot add points from different dimension"""
def __init__(self):
super().__init__(self)
self.msg='Discreapncies in dimensions. We cannot add points from different dimension'
class IsNumericError(Exception):
"""Point contains other chars than numbers"""
def __init__(self):
super().__init__(self)
self.msg='Point contains other chars than numbers'
class Point():
def __init__(self,list):
try:
if Point.is_numeric(list)!=len(list):
self.points=[]
self.isnumeric = False
raise IsNumericError()
else:
self.points=list
self.isnumeric=True
except IsNumericError as e:
print(e.msg)
def __repr__(self):
return '<Point %s, is numeric: %s>' %(self.points,self.isnumeric)
def __add__(self, other):
try:
new = []
if self.isnumeric==False or other.isnumeric==False:
raise IsNumericError()
elif len(self.points) != len(other.points):
raise DimensionError()
else:
for index in range(len(self.points)):
new.append(self.points[index]+other.points[index])
except IsNumericError as e:
print(e.msg)
except DimensionError as e:
print(e.msg)
return new
def __len__(self):
len=0
try:
if self.isnumeric==False:
raise IsNumericError()
else:
for element in self.points:
len+=1
except IsNumericError as e:
print(e.msg)
return len
@staticmethod
def is_numeric(point):
value=0
for element in point:
if isinstance(element, int) or isinstance(element, float):
value+=1
return value
def to_string(self):
point_tuple = tuple(self.points)
return str(point_tuple)
def __str__(self):
return (self.to_string())
def TestFunction():
punkt1=Point([1,2,2])
punkt2=Point([1,7,25])
print('Ilosc wymiarow: ', len(punkt1))
print('Ilość wymiarów: ', len(punkt2))
punkt3=punkt1+punkt2
print('punkt1 + punkt2 = ',punkt3)
print(punkt1.to_string(),punkt1)
print(punkt2.to_string(),punkt2)
#punkt1.__str__()
TestFunction()

297
labs05/Lab05.ipynb Normal file
View File

@ -0,0 +1,297 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Python: część 3\n",
"\n",
"## Tomasz Dwojak\n",
"\n",
"### 16 grudnia 2017"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Co już było?\n",
" * podstawowe typy i struktury danych\n",
" * funkcje\n",
" * biblioteki\n",
" * klasy\n",
" * praca z plikami\n",
" * wyjątki"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Co na dziś?\n",
" * Dzielenie kodu na pliki\n",
" * Podstawy analizy danych: Pandas"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Dzielenie kodu\n",
"\n",
" * Zwiększenie jakości kodu\n",
" * Napisz raz i korzystaj w wielu sytuacjach\n",
" * Tworzenie własnej biblioteki"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Dzielenie kodu - podsumowanie\n",
" * import\n",
" * ``if __name__ == '__main__'``\n",
" * Pakiety i pliki ``__init__.py``\n",
" * zmienna PYTHONPATH i ``sys.path``"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Interpreter Pythona"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Jupyter notebook"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Argumenty do programu\n",
"\n",
" * czy potrzebujemy pyCharm żeby uruchomić prosty skrypt?"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### sys.argv\n",
" * zawiera liste wszystkich argumentów\n",
" * pierwszy element zawiera nazwe pliku"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/usr/lib/python2.7/site-packages/ipykernel/__main__.py', '-f', '/run/user/1000/jupyter/kernel-7efdb6ca-75d5-474e-90c4-fda3dadc3282.json']\n"
]
}
],
"source": [
"import sys\n",
"print(sys.argv)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Biblioteka argparse"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import argparse\n",
"parser = argparse.ArgumentParser()\n",
"parser.parse_args()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"number\", help=\"Opis\")\n",
"args = parser.parse_args()\n",
"print(args.number)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"number\", help=\"Opis\", nargs=\"+\")\n",
"args = parser.parse_args()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"--verbosity\", help=\"increase output verbosity\")\n",
"args = parser.parse_args()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"--verbose\", help=\"increase output verbosity\",\n",
" action=\"store_true\")\n",
"args = parser.parse_args()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"-v\", \"--verbose\", help=\"increase output verbosity\",\n",
" action=\"store_true\")\n",
"args = parser.parse_args()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"-v\", \"--verbose\", help=\"increase output verbosity\",\n",
" action=\"store_true\")\n",
"parser.add_argument(\"number\", help=\"Opis\", nargs=\"+\")\n",
"args = parser.parse_args()"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 2",
"language": "python2",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

20
labs05/README.md Normal file
View File

@ -0,0 +1,20 @@
** zad. 0 **
Napisz funkcję ``suma``, która przyjmnie jeden argument: listę liczb i zwróci ich sumę.
** zad. 1 **
Zaimportuj z zadania 0 fukcje ``suma``. Korzystając z tej fukcji i tablicy ``sys.argv`` oblicz i wyświetl sumę argumentów, jakie zostały przekazane do proramu. Załóź, że argumentami do programu będą tylko liczby zmiennoprzecinkowe.
** zad. 2 **
Uodpornoj program z zad. 1 w następujący sposób: do programu mogą zostać przekazane argumenty, które nie mają wartości liczbowej (przyjmijmy, że ich wartość to 0). Skorzystaj z mechanizmu wyjątków: złap wyjątek, jeżeli argumenty nie da się skonwertować na liczbę zmiennoprzecinkową.
** zad. 3 **
Przekształć rozwiązanie zadania drugiego w taki sposob, żeby korzystało z biblioteki ``argparse`` zamiast z z listy ``sys.argv``.
** zad. 4 (Domowe) **
Plik ``task04.py`` zawiera kod prorgamu, który działa jak popularne narzędzie unixowe ``wc`` (Word Counter): zlicza liczbę linii, wyrazów i znaków. Aktualnie program potrafi działać wyłącznie na wejściu podanym z klawiatury. Dodaj do niego opcje programu:
* domyślnie program ma zliczać na wejściu z klawiatury (stdin) i wyświetlać wszystkie 3 liczby.
* Jeżeli został podany przełącznik `-l`, to to ma zostać zwrócona tylko liczba linii.
* Jeżeli został podany przełącznik `-w`, to to ma zostać zwrócona tylko liczba słów.
* Jeżeli został podany przełącznik `-c`, to to ma zostać zwrócona tylko liczba znaków.
* Jeżeli został podany inny argument, to należy założyć że jest to nazwa pliku i potraktować ten plik jako wejście do programu.

0
labs05/__init__.py Normal file
View File

29
labs05/argparse_min.py Normal file
View File

@ -0,0 +1,29 @@
import argparse
parser = argparse.ArgumentParser()
parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("number", help="Opis")
# args = parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("number", help="Opis", nargs="+")
# args = parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("--verbosity", help="increase output verbosity")
# args = parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("--verbose", help="increase output verbosity",
# action="store_true")
# args = parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("-v", "--verbose", help="increase output verbosity",
# action="store_true")
# parser.add_argument("number", help="Opis", nargs="+")
# args = parser.parse_args()

11
labs05/lib.py Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def greetings():
print("Pozdrowienia!!!")
print("SPAM " * 6)
print(__name__)
if __name__ == '__main__':
print("Jestem głównym plikiem!")

18
labs05/main.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import lib
import tools.fib
import sys
# sys.path.append("..")
# import labs02.task01
def main():
print("Hello World")
lib.greetings()
print(tools.fib.non_reccurent_fibonacci(50))
if __name__ == '__main__':
main()

15
labs05/task00.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Napisz funkcję ``suma``, która przyjmnie jeden argument: listę liczb i zwróci ich sumę.
"""
def suma(liczby):
return sum(liczby)
def main():
print(suma([1, 2, 3, 4]))
if __name__ == "__main__":
main()

22
labs05/task01.py Normal file
View File

@ -0,0 +1,22 @@
"""
** zad. 1 **
Zaimportuj z zadania 0 fukcje ``suma``. Korzystając z tej fukcji i tablicy ``sys.argv`` oblicz i wyświetl sumę argumentów,
jakie zostały przekazane do proramu. Załóź, że argumentami do programu będą tylko liczby zmiennoprzecinkowe.
"""
from task00 import suma
import sys
def main():
arguments=sys.argv[1:]
float_arguments=[]
for arg in arguments:
float_arguments.append(float(arg))
print(suma(float_arguments))
if __name__ == '__main__':
main()

25
labs05/task02.py Normal file
View File

@ -0,0 +1,25 @@
"""
** zad. 2 **
Uodpornoj program z zad. 1 w następujący sposób: do programu mogą zostać przekazane argumenty, które nie mają wartości liczbowej (przyjmijmy, że ich wartość to 0).
Skorzystaj z mechanizmu wyjątków: złap wyjątek, jeżeli argumenty nie da się skonwertować na liczbę zmiennoprzecinkową.
"""
from task00 import suma
import sys
def main():
arg_list = sys.argv[1:]
float_arg_list = []
for arg in arg_list:
try:
float_arg=float(arg)
float_arg_list.append(float_arg)
except:
float_arg_list.append(0)
print(suma(float_arg_list))
if __name__ == '__main__':
main()

0
labs05/task03.py Normal file
View File

70
labs05/task04.py Normal file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Implementacja narzedzia ``wc`` z linuksa (word counter).
Zwraca liczbę słów, znaków i linii.
** zad. 4 (Domowe) **
Plik ``task04.py`` zawiera kod prorgamu, który działa jak popularne narzędzie unixowe ``wc`` (Word Counter): zlicza liczbę linii, wyrazów i znaków.
Aktualnie program potrafi działać wyłącznie na wejściu podanym z klawiatury. Dodaj do niego opcje programu:
* domyślnie program ma zliczać na wejściu z klawiatury (stdin) i wyświetlać wszystkie 3 liczby.
* Jeżeli został podany przełącznik `-l`, to to ma zostać zwrócona tylko liczba linii.
* Jeżeli został podany przełącznik `-w`, to to ma zostać zwrócona tylko liczba słów.
* Jeżeli został podany przełącznik `-c`, to to ma zostać zwrócona tylko liczba znaków.
* Jeżeli został podany inny argument, to należy założyć że jest to nazwa pliku i potraktować ten plik jako wejście do programu.
"""
import sys
import argparse
def count_lines(text):
""" return number of lines. """
return len(text.strip().split('\n'))
def count_words(text):
""" return number of words. """
return sum([len([1 for word in line.split(' ') if len(word)])
for line in text.split('\n')])
def count_chars(text):
""" return number of characters. """
return len(text)
def wc(text):
""" proper wc """
lines = count_lines(text)
words = count_words(text)
chars = count_chars(text)
return lines, words, chars
def main():
""" main """
parser = argparse.ArgumentParser()
parser.add_argument('-l', help="number of lines", action="store_true")
parser.add_argument('-w', help="number of words", action="store_true")
parser.add_argument('-c', help="number of chars", action="store_true")
parser.add_argument('-filename', type=argparse.FileType('r'), default='-', help='filename to read from')
args = parser.parse_args()
if args.filename:
lines, words, chars = wc(args.filename.read())
elif not sys.stdin.isatty():
lines, words, chars = wc(args.stdin.read())
else:
pass
if(args.l):
print(lines)
elif(args.w):
print(words)
elif(args.c):
print(chars)
else:
print(lines, words, chars)
if __name__ == "__main__":
main()

0
labs05/tools/__init__.py Normal file
View File

38
labs05/tools/fib.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Obliczenie n-tego wyrazu ciągu fibonacciego na dwa sposoby.
1. Naiwna rekurencja: podstawienie do wzoru.
2. Wersja z cachem: każdy wyraz jest obliczany dokładnie raz.
"""
def naive_fibonacci(n):
if n <= 0:
return 0
if n in [1,2]:
return 1
return naive_fibonacci(n-1) + naive_fibonacci(n-2)
def cache_fibonacci(n, cache=None):
if cache is None:
cache = [None for i in range(n+1)]
cache[0] = 0
cache[1] = cache[2] = 1
return cache_fibonacci(n, cache)
else:
if cache[n] is not None:
return cache[n]
else:
cache[n] = cache_fibonacci(n-1, cache) + cache_fibonacci(n-2, cache)
return cache[n]
def non_reccurent_fibonacci(n):
cache = [None for i in range(n+1)]
cache[0] = 0
cache[1] = cache[2] = 1
for i in range(2, n + 1):
cache[i] = cache[i-1] + cache[i-2]
return cache[n]

874
labs06/Pandas.ipynb Normal file

File diff suppressed because one or more lines are too long

18
labs06/README.md Normal file
View File

@ -0,0 +1,18 @@
## Zadania
** zad. 0 **
Sprawdź, czy masz zainstalowany pakiet ``pandas``. Jeżeli nie, zainstaluj go.
** zad. 2 (domowe) **
Jest to zadanie złożone, składające się z kilku części. Całość będzie opierać się o dane zawarte w pliku *mieszkania.csv* i dotyczą cen mieszkań w Poznaniu kilka lat temu.
1, Otwórz plik ``task02.py``, który zawiera szkielet kodu, który będziemy rozwijać w tym zadaniu.
1. Napisz funkcje, która wczyta zestaw danych z pliku *mieszkania.csv* i zwróci obiekt typu *DataFrame*. Jeżeli wszystko zostało zrobione poprawnie, powinno się wyśtwietlić 5 pierwszych wierszy.
1. Uzupełnij funkcję ``most_common_room_number``, która zwróci jaka jest najpopularniejsza liczba pokoi w ogłoszeniach. Funkcji powinna zwrócić liczbę całkowitą.
1. Uzupełnij kod w funkcji ``cheapest_flats(dane, n)``, która wzróci *n* najtańszych ofert mieszkań. Wzrócony obiekt typu ``DataFrame``.
1. Napisz funkcje ``find_borough(desc)``, która przyjmuje 1 argument typu *string* i zwróci jedną z dzielnic zdefiniowaną w liście ``dzielnice``. Funkcja ma zwrócić pierwszą (wzgledem kolejności) nazwę dzielnicy, która jest zawarta w ``desc``. Jeżeli żadna nazwa nie została odnaleziona, zwróć *Inne*.
1. Dodaj kolumnę ``Borough``, która będzie zawierać informacje o dzielnicach i powstanie z kolumny ``Localization``. Wykorzystaj do tego funkcję ``find_borough``.
1. Uzupełnił funkcje ``write_plot``, która zapisze do pliku ``filename`` wykres słupkowy przedstawiający liczbę ogłoszeń mieszkań z podziałem na dzielnice.
1. Napisz funkcje ``mean_price``, która zwróci średnią cenę mieszkania ``room_numer``-pokojowego.
1. Uzupełnij funkcje ``find_13``, która zwróci listę dzielnic, które zawierają ofertę mieszkanie na 13 piętrze.
1. Napisz funkcje ``find_best_flats``, która zwróci wszystkie ogłoszenia mieszkań, które znajdują się na Winogradach, mają 3 pokoje i są położone na 1 piętrze.
1. *(dodatkowe)*: Korzystając z pakietu *sklearn* zbuduj model regresji liniowej, która będzie wyznaczać cenę mieszkania na podstawie wielkości mieszkania i liczby pokoi.

311
labs06/bikes.csv Normal file
View File

@ -0,0 +1,311 @@
Date;Berri 1;Brébeuf (données non disponibles);Côte-Sainte-Catherine;Maisonneuve 1;Maisonneuve 2;du Parc;Pierre-Dupuy;Rachel1;St-Urbain (données non disponibles)
01/01/2012;35;;0;38;51;26;10;16;
02/01/2012;83;;1;68;153;53;6;43;
03/01/2012;135;;2;104;248;89;3;58;
04/01/2012;144;;1;116;318;111;8;61;
05/01/2012;197;;2;124;330;97;13;95;
06/01/2012;146;;0;98;244;86;4;75;
07/01/2012;98;;2;80;108;53;6;54;
08/01/2012;95;;1;62;98;64;11;63;
09/01/2012;244;;2;165;432;198;12;173;
10/01/2012;397;;3;238;563;275;18;241;
11/01/2012;273;;0;182;443;258;12;194;
12/01/2012;157;;1;134;261;137;9;63;
13/01/2012;75;;0;41;105;64;2;0;
14/01/2012;32;;0;54;56;19;0;1;
15/01/2012;54;;0;33;60;18;0;0;
16/01/2012;168;;2;136;312;137;1;0
17/01/2012;155;;0;86;256;74;0;0
18/01/2012;139;;0;66;188;68;3;0
19/01/2012;191;;1;104;248;79;3;0
20/01/2012;161;;4;96;217;67;1;1
21/01/2012;53;;0;47;70;32;1;0
22/01/2012;71;;0;41;73;35;5;0
23/01/2012;210;;6;114;357;91;6;0
24/01/2012;299;;1;189;444;174;4;0
25/01/2012;334;;1;217;453;180;4;0
26/01/2012;306;;0;215;495;191;0;1
27/01/2012;91;;5;79;204;65;0;0
28/01/2012;80;;1;61;123;33;9;1
29/01/2012;87;;1;65;132;40;7;0
30/01/2012;219;;0;146;371;152;2;0
31/01/2012;186;;1;109;324;122;0;0
01/02/2012;138;;0;100;271;71;5;0
02/02/2012;217;;5;134;345;128;2;2
03/02/2012;174;;1;103;301;111;1;1
04/02/2012;84;;0;53;119;44;8;0
05/02/2012;72;;0;46;133;54;7;0
06/02/2012;248;;1;136;425;167;10;0
07/02/2012;316;;0;209;516;225;9;0
08/02/2012;271;;0;202;503;215;4;1
09/02/2012;342;;0;227;471;231;11;0
10/02/2012;303;;1;206;478;216;6;2
11/02/2012;71;;0;63;112;49;3;0
12/02/2012;78;;0;36;91;53;5;0
13/02/2012;211;;0;175;408;207;4;0
14/02/2012;318;;0;186;504;243;9;1
15/02/2012;307;;0;180;491;232;5;1
16/02/2012;386;;1;212;569;295;10;0
17/02/2012;332;;3;237;496;260;11;1
18/02/2012;220;;1;159;280;134;30;0
19/02/2012;169;;3;110;205;113;13;2
20/02/2012;303;;2;224;470;243;14;10
21/02/2012;441;;5;292;503;286;10;6
22/02/2012;375;;10;263;501;264;12;3
23/02/2012;397;;10;293;528;329;22;13
24/02/2012;243;;4;187;313;137;4;13
25/02/2012;62;;0;48;52;18;2;5
26/02/2012;78;;0;76;47;35;4;0
27/02/2012;119;;4;94;298;134;3;5
28/02/2012;195;;0;158;350;168;9;3
29/02/2012;242;;0;164;446;190;7;4
01/03/2012;92;;0;56;199;63;0;14
02/03/2012;143;;0;56;283;77;7;1
03/03/2012;82;;0;65;133;47;2;0
04/03/2012;107;;2;79;138;60;15;0
05/03/2012;155;;1;114;363;157;8;2
06/03/2012;269;;0;192;437;170;10;0
07/03/2012;438;;3;290;715;266;28;0
08/03/2012;348;;6;238;530;270;9;9
09/03/2012;371;;8;279;575;268;8;38
10/03/2012;182;;13;162;296;165;0;58
11/03/2012;380;;60;253;540;289;0;285
12/03/2012;802;;179;618;1265;747;0;548
13/03/2012;442;;145;321;769;425;0;325
14/03/2012;469;;146;313;739;451;0;336
15/03/2012;724;;244;562;1021;631;63;565
16/03/2012;423;;149;305;695;419;9;422
17/03/2012;681;;287;422;872;468;334;1008
18/03/2012;1940;;856;1036;1923;1021;1128;2477
19/03/2012;1821;;1024;1278;2581;1609;506;2058
20/03/2012;2481;;1261;1709;3130;1955;762;2609
21/03/2012;2829;;1558;1893;3510;2225;993;2846
22/03/2012;2195;;1030;1640;2654;1958;548;2254
23/03/2012;2115;;1143;1512;2955;1791;663;2325
24/03/2012;753;;336;517;1001;635;277;1035
25/03/2012;520;;243;309;691;427;145;723
26/03/2012;968;;564;729;1493;965;130;1168
27/03/2012;1049;;517;774;1576;972;163;1207
28/03/2012;435;;179;329;709;486;28;529
29/03/2012;878;;406;646;1264;807;78;937
30/03/2012;1157;;529;910;1596;957;196;1288
31/03/2012;980;;499;587;1083;706;524;1370
01/04/2012;662;;341;442;824;471;168;1086
02/04/2012;1937;;967;1537;2853;1614;394;2122
03/04/2012;2416;;1078;1791;3556;1880;513;2450
04/04/2012;2211;;933;1674;2956;1666;274;2242
05/04/2012;2424;;1036;1823;3273;1699;355;2463
06/04/2012;1633;;650;1045;1913;975;621;2138
07/04/2012;1208;;494;739;1445;709;598;1566
08/04/2012;1164;;560;621;1333;704;792;1533
09/04/2012;828;;298;560;1048;605;65;1001
10/04/2012;2183;;909;1588;2932;1736;252;2108
11/04/2012;2328;;1049;1765;3122;1843;330;2311
12/04/2012;3064;;1483;2306;4076;2280;590;3213
13/04/2012;3341;;1505;2565;4465;2358;922;3728
14/04/2012;2890;;1072;1639;2994;1594;1284;3428
15/04/2012;2554;;1210;1637;2954;1559;1846;3604
16/04/2012;3643;;1841;2723;4830;2677;1061;3616
17/04/2012;3539;;1616;2636;4592;2450;544;3333
18/04/2012;3570;;1751;2759;4655;2534;706;3542
19/04/2012;4231;;2010;3235;5311;2877;1206;3929
20/04/2012;2087;;800;1529;2922;1531;170;2065
21/04/2012;533;;212;398;710;408;50;755
22/04/2012;1853;;487;1224;1331;654;198;1779
23/04/2012;623;;315;544;1076;612;27;846
24/04/2012;1810;;720;1355;2379;1286;188;1753
25/04/2012;2966;;1023;2228;3444;1800;445;2454
26/04/2012;2751;;1069;2196;3546;1789;381;2438
27/04/2012;1986;;743;1526;2586;1298;139;1899
28/04/2012;1684;;628;1190;1908;931;523;2323
29/04/2012;1970;;765;1212;2077;1062;702;2493
30/04/2012;3610;;1572;2825;4675;2446;851;3541
01/05/2012;1986;;815;1722;2766;1516;195;1960
02/05/2012;3724;;1677;2885;4731;2508;876;3501
03/05/2012;3698;;1618;3001;4943;2577;731;3603
04/05/2012;2511;;1163;2058;3717;1823;380;2631
05/05/2012;3492;;1366;2106;3696;1779;1677;4108
06/05/2012;3411;;1525;1815;3346;1879;2036;4633
07/05/2012;5552;;2573;3959;6355;3416;1848;5253
08/05/2012;1241;;625;991;1729;1007;119;1383
09/05/2012;3297;;1545;2700;4343;2340;737;3129
10/05/2012;2755;;1227;2130;4056;2075;399;2437
11/05/2012;4639;;1803;3663;5713;2888;1260;4499
12/05/2012;3854;;1457;2429;3894;1805;2268;4855
13/05/2012;2741;;1223;1703;3086;1592;1394;3496
14/05/2012;6189;;2709;4402;7006;3868;2215;5775
15/05/2012;3964;;1773;3144;5088;2650;975;3765
16/05/2012;4947;;2178;3681;5882;3057;1332;4348
17/05/2012;5351;;2441;4182;6551;3408;1631;4988
18/05/2012;5980;;2241;4415;6646;3196;1711;5273
19/05/2012;4732;;1454;2807;4673;1966;2914;5293
20/05/2012;5255;;1663;2730;4462;2182;4241;5539
21/05/2012;5129;;1646;2672;4169;2044;3413;5053
22/05/2012;2315;;938;1847;2599;1610;251;2069
23/05/2012;5974;;2650;4407;7281;3737;1826;4798
24/05/2012;6485;;2653;4600;7600;3792;2062;5209
25/05/2012;5697;;2205;4096;6734;3341;1953;5174
26/05/2012;4974;;1622;2936;4991;2373;3455;5443
27/05/2012;4396;;1525;2578;4587;2073;2886;5168
28/05/2012;4268;;1962;3449;5798;2898;1027;3894
29/05/2012;3154;;1184;2325;3904;1933;475;2731
30/05/2012;6459;;2722;4806;7632;3817;2454;5172
31/05/2012;5104;;2177;3985;6631;3205;1389;4410
01/06/2012;6097;;2604;4110;7175;3895;1692;6595
02/06/2012;943;;392;630;1289;628;71;1436
03/06/2012;2755;;1897;2020;3768;2324;1312;4936
04/06/2012;2717;;1408;2095;4276;2168;333;3090
05/06/2012;5842;;2721;3927;7302;3786;1232;5348
06/06/2012;6037;;2724;4273;7822;3987;1223;5269
07/06/2012;6246;;2607;4670;8222;3972;1019;5724
08/06/2012;4169;;1833;3303;5881;3001;623;4474
09/06/2012;5164;;1672;3418;5557;2451;1551;6026
10/06/2012;5112;;1812;2905;4798;2328;1833;6170
11/06/2012;6206;;2577;4333;7015;3757;1264;5721
12/06/2012;3361;;1556;2362;4230;2381;589;3030
13/06/2012;6180;;2792;4374;7297;3825;1968;5887
14/06/2012;6908;;2978;4809;7934;4223;2386;6243
15/06/2012;7077;;2469;4999;7663;4053;2293;6491
16/06/2012;5421;;1651;3099;4909;2337;3280;5537
17/06/2012;4638;;1552;2082;4108;2020;3453;5128
18/06/2012;5921;;2703;3582;6824;3960;2455;5496
19/06/2012;5382;;2360;3447;6679;3438;1711;5015
20/06/2012;5713;;2402;3524;6848;3510;2363;4852
21/06/2012;5183;;2195;3297;6684;3272;2265;4957
22/06/2012;5398;;1934;3612;6659;3252;2009;5263
23/06/2012;3753;;1326;1842;3992;1910;2585;4824
24/06/2012;3341;;1152;1423;2989;1510;3634;4581
25/06/2012;2245;;1077;1374;3031;1440;1349;3283
26/06/2012;3327;;1435;2139;4318;2193;620;3223
27/06/2012;3141;;1322;2142;4211;2134;536;2897
28/06/2012;6064;;2381;4411;6864;3523;2415;5175
29/06/2012;5770;;1935;4004;6656;3090;2109;5332
30/06/2012;4738;;1359;3007;4226;1822;2870;4527
01/07/2012;4758;;1343;2911;3935;1777;3732;4522
02/07/2012;4144;;1397;2658;3998;1883;2783;4464
03/07/2012;6712;;2634;4398;7416;3896;2606;5462
04/07/2012;5153;;2038;3591;5814;3070;1246;4493
05/07/2012;6672;;2603;4830;7764;3816;2746;5153
06/07/2012;5958;;2095;4137;6942;3387;2248;5610
07/07/2012;5420;;1289;3802;4978;2132;3156;4939
08/07/2012;4756;;1497;2407;4495;2089;4386;5535
09/07/2012;5661;;2330;3524;6769;3577;2599;4987
10/07/2012;6500;;2625;4064;7436;3749;2822;5952
11/07/2012;6424;;2548;3921;7374;3781;2779;5474
12/07/2012;6179;;2371;3772;7200;3687;2433;5140
13/07/2012;5518;;2005;3525;6492;3088;2219;5185
14/07/2012;4206;;1244;2441;4284;1562;2900;4252
15/07/2012;3035;;1060;1798;3437;1449;2034;3545
16/07/2012;4827;;2092;3141;6049;2965;1703;4379
17/07/2012;2756;;1046;2001;3802;1700;569;2641
18/07/2012;6180;;2589;3750;7311;3654;2813;5884
19/07/2012;6309;;2397;3996;7699;3777;2647;5665
20/07/2012;5813;;2088;3744;6959;3316;2538;5775
21/07/2012;5092;;1419;2957;4658;1821;3835;4848
22/07/2012;4971;;1238;2683;4104;1788;2960;4787
23/07/2012;3877;;1660;2420;4937;2534;1461;3475
24/07/2012;5243;;2318;3465;6721;3317;2170;4694
25/07/2012;6104;;2593;3786;7073;3622;3132;5059
26/07/2012;5560;;2043;4174;6476;3208;1595;4383
27/07/2012;5759;;1948;3658;6851;3275;2653;5295
28/07/2012;4105;;1345;2504;4540;1767;2468;4631
29/07/2012;4230;;1332;1791;4235;1905;3731;4906
30/07/2012;5225;;2285;2975;6219;3196;2564;5100
31/07/2012;5415;;2185;3145;6705;3222;2505;4468
01/08/2012;4638;;1842;2783;5846;2810;1481;3889
02/08/2012;5715;;2361;3340;6956;3329;2643;4828
03/08/2012;5577;;1915;3306;6427;2789;3195;5031
04/08/2012;4223;;1305;2019;4425;1769;2939;4467
05/08/2012;1864;;630;1100;2327;970;1066;2268
06/08/2012;5240;;2277;3193;6375;3187;2274;4604
07/08/2012;5997;;2410;3622;6840;3480;2780;4903
08/08/2012;5498;;2313;3365;6862;3403;2226;4771
09/08/2012;4127;;1802;2601;5377;2656;1471;3636
10/08/2012;2414;;934;1727;3323;1641;440;2456
11/08/2012;2453;;815;1589;2628;1043;1340;2608
12/08/2012;3995;;1338;1937;3427;1719;2988;4178
13/08/2012;4931;;2298;3124;5936;3151;2090;4842
14/08/2012;5333;;2322;3571;6332;3260;1456;4362
15/08/2012;4297;;1882;2936;4948;2686;970;3877
16/08/2012;6062;;2538;3898;6549;3366;1549;4943
17/08/2012;4236;;1777;3099;4979;2581;586;4154
18/08/2012;4427;;1333;2505;3866;1864;1229;4359
19/08/2012;4644;;1408;2605;3780;1758;1683;4478
20/08/2012;5335;;2474;3521;6088;3332;1439;5201
21/08/2012;5792;;2508;4063;6687;3369;2353;5640
22/08/2012;6529;;2671;4513;7065;3774;2391;5154
23/08/2012;5437;;2482;3807;6773;3573;1864;5010
24/08/2012;5690;;2394;3778;6703;3312;2178;5299
25/08/2012;4242;;1305;2358;4126;1726;2558;4833
26/08/2012;3964;;1318;2118;3558;1750;2932;4536
27/08/2012;4314;;2273;3098;5196;2762;1010;3598
28/08/2012;5817;;2794;3966;6313;3420;1629;4720
29/08/2012;6327;;3092;4370;7009;3759;2152;5342
30/08/2012;6003;;2910;4199;6781;3481;1796;5202
31/08/2012;4106;;1868;2999;5054;2541;875;4188
01/09/2012;3934;;1225;2371;3917;1887;2801;3845
02/09/2012;3698;;1232;2093;3827;1788;2959;4247
03/09/2012;4179;;1532;2233;3718;1620;3783;4709
04/09/2012;4225;;1934;3057;5275;3006;894;3868
05/09/2012;5655;;2722;3861;7110;4061;1383;4491
06/09/2012;5883;;2883;3967;7511;4014;1498;4732
07/09/2012;6186;;2720;4153;7323;3886;2051;6104
08/09/2012;2155;;1192;1467;2739;898;801;2626
09/09/2012;3312;;1810;1828;3458;2668;2118;4355
10/09/2012;5077;;2792;3718;6644;3849;1271;4984
11/09/2012;6015;;2913;4081;7148;4314;1484;5451
12/09/2012;6349;;3124;4209;7292;4510;1981;5697
13/09/2012;6520;;3076;4369;7514;4494;1986;5742
14/09/2012;5216;;2257;3480;6104;3574;1524;4918
15/09/2012;3341;;1100;1900;3099;1593;1268;3426
16/09/2012;3635;;1231;1614;3040;1852;2348;3696
17/09/2012;5299;;2658;3670;6582;4076;1704;4788
18/09/2012;2530;;1277;1695;3254;2275;388;2377
19/09/2012;4653;;2351;3176;5746;3738;840;4189
20/09/2012;5260;;2496;3615;6348;3991;1391;5119
21/09/2012;4022;;1821;2911;4745;2945;889;3886
22/09/2012;1521;;656;1073;1682;971;365;1974
23/09/2012;2314;;1093;1496;2572;1470;984;3321
24/09/2012;4553;;2246;3117;5738;3705;1100;4683
25/09/2012;5038;;2236;3273;5861;3712;1007;4420
26/09/2012;3948;;1873;2720;4755;3119;650;3721
27/09/2012;5119;;2288;3465;5983;3704;1152;4598
28/09/2012;4652;;2134;3209;5372;3309;1133;4361
29/09/2012;1896;;755;1206;1963;1062;442;2267
30/09/2012;876;;359;513;957;520;133;1162
01/10/2012;3255;;1576;2184;3830;2582;397;2987
02/10/2012;5139;;2525;3281;5845;3732;1229;4497
03/10/2012;4685;;2377;3191;5475;3415;858;3941
04/10/2012;4034;;2025;2705;4850;3066;555;3418
05/10/2012;4151;;1977;2799;4688;2844;1035;4088
06/10/2012;1304;;469;933;1589;776;236;1775
07/10/2012;1580;;660;922;1629;860;695;2052
08/10/2012;1854;;880;987;1818;1040;1115;2502
09/10/2012;4787;;2210;3026;5138;3418;927;4078
10/10/2012;3115;;1537;2081;3681;2608;560;2703
11/10/2012;3746;;1857;2569;4694;3034;558;3457
12/10/2012;3169;;1460;2261;4045;2564;448;3224
13/10/2012;1783;;802;1205;2113;1183;681;2309
14/10/2012;587;;287;443;852;503;65;952
15/10/2012;3292;;1678;2165;4197;2754;560;3183
16/10/2012;3739;;1858;2684;4681;2997;554;3593
17/10/2012;4098;;1964;2645;4836;3063;728;3834
18/10/2012;4671;;2292;3129;5542;3477;1108;4245
19/10/2012;1313;;597;885;1668;1209;111;1486
20/10/2012;2011;;748;1323;2266;1213;797;2243
21/10/2012;1277;;609;869;1777;898;242;1648
22/10/2012;3650;;1819;2495;4800;3023;757;3721
23/10/2012;4177;;1997;2795;5216;3233;795;3554
24/10/2012;3744;;1868;2625;4900;3035;649;3622
25/10/2012;3735;;1815;2528;5010;3017;631;3767
26/10/2012;4290;;1987;2754;5246;3000;1456;4578
27/10/2012;1857;;792;1244;2461;1193;618;2471
28/10/2012;1310;;697;910;1776;955;387;1876
29/10/2012;2919;;1458;2071;3768;2440;411;2795
30/10/2012;2887;;1251;2007;3516;2255;338;2790
31/10/2012;2634;;1294;1835;3453;2220;245;2570
01/11/2012;2405;;1208;1701;3082;2076;165;2461
02/11/2012;1582;;737;1109;2277;1392;97;1888
03/11/2012;844;;380;612;1137;713;105;1302
04/11/2012;966;;446;710;1277;692;197;1374
05/11/2012;2247;;1170;1705;3221;2143;179;2430
Can't render this file because it has a wrong number of fields in line 17.

5001
labs06/mieszkania.csv Normal file

File diff suppressed because it is too large Load Diff

88
labs06/task02.py Normal file
View File

@ -0,0 +1,88 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import statistics
def wczytaj_dane():
raw_data = pd.read_csv('mieszkania.csv',sep=',')
data = pd.DataFrame(raw_data)
return data
def most_common_room_number(dane):
rooms=dane['Rooms']
return(int(statistics.mode(rooms)))
def cheapest_flats(dane, n):
cheapest=pd.DataFrame(dane['Expected'])
cheapest.sort=cheapest.sort_values(by=['Expected'])
return cheapest.sort[:n]
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
for dzielnica in dzielnice:
if desc.find(dzielnica)!=-1:
return dzielnica
return 'Inne'
def add_borough(dane):
borough_list=[]
for data in dane['Location']:
borough_list.append(find_borough(data))
borough_series = pd.Series(borough_list,name='Borough')
dane['Borough']=borough_series
return dane
def write_plot(dane, filename):
data = add_borough(dane)
plot_data = data.groupby(dane['Borough']).size()
plt = plot_data.plot.bar()
fig = plt.get_figure()
fig.savefig('{}.png'.format(filename))
return 0
def mean_price(dane, room_number):
data=dane.loc[dane['Rooms'] == room_number]
return round(statistics.mean(data['Expected']),2)
def find_13(dane):
data = add_borough(dane)
boroughs = data.loc[data['Floor'] == 13]
return set(boroughs['Borough'])
def find_best_flats(dane):
data = add_borough(dane)
best_flats = data.loc[(data['Borough'] == 'Winogrady') & (data['Floor'] == 1) & (data['Rooms'] == 3)]
return best_flats
def main():
dane = wczytaj_dane()
print(dane[:5])
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
.format(most_common_room_number(dane)))
print("{} to najłądniejsza dzielnica w Poznaniu."
.format(find_borough("Grunwald i Jeżyce")))
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3)))
if __name__ == "__main__":
main()