Compare commits

...

19 Commits

Author SHA1 Message Date
5238249af5 Poprawione ćw 3 2018-01-22 19:14:29 +01:00
689e3bc8ee Homework#6 2018-01-20 15:40:45 +01:00
ba9dc1422a Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017 2018-01-17 20:34:07 +01:00
00d565690f Homework#2 2017-12-15 17:50:29 +01:00
e7c555cd6a Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-03 15:35:32 +01:00
417669ce28 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-03 15:20:59 +01:00
169b8cb51f Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-03 15:20:49 +01:00
58ec99c4ad Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017 2017-12-03 13:32:43 +01:00
27d6fb7c7b Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:44:04 +01:00
881ce4306e Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:43:33 +01:00
dcd13d8f6d Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:35:28 +01:00
4a20298ab2 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:35:13 +01:00
8eda90d9f8 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:33:48 +01:00
ac68c51136 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:28:53 +01:00
5fbc3b57d4 Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:28:00 +01:00
505e2aa30c Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts:
#	labs02/test_task.py
2017-12-02 15:26:26 +01:00
c6a24f1f8e ćwiczenia 1.1 2017-11-30 21:11:34 +01:00
86d33a2a5d ćwiczenia 1.1 2017-11-30 20:12:25 +01:00
47b7c62adf ćwiczenia 1 2017-11-19 15:44:48 +01:00
28 changed files with 291 additions and 253 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.6.2 (C:\software\python3\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

@ -7,8 +7,9 @@ która zawiera tylko elementy z list o parzystych indeksach.
""" """
def even_elements(lista): def even_elements(lista):
pass return lista[::2]
print(even_elements([1,2,3,4]))
def tests(f): def tests(f):
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]] inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
@ -23,3 +24,5 @@ def tests(f):
if __name__ == "__main__": if __name__ == "__main__":
print(tests(even_elements)) print(tests(even_elements))

View File

@ -6,7 +6,13 @@
""" """
def days_in_year(days): def days_in_year(days):
pass if (days % 4 == 0 and days % 100 != 0) or days % 400 == 0:
return 366
else:
return 365
print("dni:",days_in_year(2000))
def tests(f): def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]] inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -10,11 +10,21 @@ znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na mał
litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
jak 'set', która przechowuje elementy bez powtórzeń.) jak 'set', która przechowuje elementy bez powtórzeń.)
""" """
"""
a = []
text = "dom dla lalek"
a = text.split(' ')
print(a[1])
"""
def oov(text,vocab):
b = set()
a = text.split(' ')
for wyr in a:
if wyr not in vocab:
b.add(wyr)
return b
print(oov("Dom dla kasia", "lalek dom"))
def oov(text, vocab):
pass
def tests(f): def tests(f):

View File

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

View File

@ -10,7 +10,11 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
""" """
def euclidean_distance(x, y): def euclidean_distance(x, y):
pass if len(x)!=len(y):
return 'Error'
else:
return ((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/2)
def tests(f): def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]] inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

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

View File

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

View File

@ -7,7 +7,12 @@ przez 3 lub 5 mniejszych niż n.
""" """
def sum_div35(n): def sum_div35(n):
pass sum=0
for i in range(n):
if (i%5==0) or (i%3==0):
sum+=i
return sum
def tests(f): def tests(f):
inputs = [[10], [100], [3845]] inputs = [[10], [100], [3845]]

View File

@ -9,7 +9,15 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text): def leet_speak(text):
pass tekst=""
slownik = {"e": "3", "l": "1", "o": "0", "t":"7"}
for i in text:
if i in slownik:
tekst+=slownik[i]
else:
tekst+=i
return tekst
def tests(f): def tests(f):

View File

@ -9,7 +9,14 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text): def pokemon_speak(text):
pass s=""
for i in range(len(text)):
if (i%2==0):
s+=text[i].upper()
else:
s+=text[i]
return s
def tests(f): def tests(f):

View File

@ -9,8 +9,11 @@ Oba napisy będą składać się wyłacznie z małych liter.
""" """
def common_chars(string1, string2): def common_chars(string1, string2):
pass b =[]
for i in sorted(string1):
if (i in sorted(string2)) and i!=" " and i not in b:
b.append(i)
return b
def tests(f): def tests(f):
inputs = [["this is a string", "ala ma kota"]] inputs = [["this is a string", "ala ma kota"]]

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
return a + b
def tests(f):
inputs = [(2, 3), (0, 0), (1, 1)]
outputs = [5, 0, 2]
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
print(tests(suma))

View File

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

View File

@ -27,7 +27,10 @@ Zainstaluj bibliotekę ``weather-api`` (https://pypi.python.org/pypi/weather-api
* Korzystając z prognozy, znajdź dzień, w którym będzie najzimniej. Wypisz nazwę tygodnia (w języku polskim) i temperaturę w C. * Korzystając z prognozy, znajdź dzień, w którym będzie najzimniej. Wypisz nazwę tygodnia (w języku polskim) i temperaturę w C.
**ćwiczenie 5** **ćwiczenie 5**
Katalog scores zawiera 64 pliki tekstowe, które posiadają informacje o wysokości miary ``BLEU`` na różnych etapach trenowania modelu. Nazwa każdego pliku na postać ``model.iterXXXXXXX.npz.bleu``, gdzie ``XXXXXXX``, to liczba iteracji.Zawartość każdego pliku jest podobna i ma następującą formę: *BLEU = YY.YY, 44.4/18.5/9.3/5.0 (BP=1.000, ratio=1.072, hyp_len=45976, ref_len=42903)*, gdzie ``YY.YY`` to wartość miary ``BLEU``. Znajdź plik, który zawiera najwyższą wartość miary ``BLEU``. Katalog scores zawiera 64 pliki tekstowe, które posiadają informacje o wysokości miary ``BLEU``
na różnych etapach trenowania modelu. Nazwa każdego pliku na postać ``model.iterXXXXXXX.npz.bleu``, gdzie ``XXXXXXX``,
to liczba iteracji.Zawartość każdego pliku jest podobna i ma następującą formę: *BLEU = YY.YY, 44.4/18.5/9.3/5.0 (BP=1.000,
ratio=1.072, hyp_len=45976, ref_len=42903)*, gdzie ``YY.YY`` to wartość miary ``BLEU``. Znajdź plik, który zawiera najwyższą wartość miary ``BLEU``.
* Wykorzystaj bibliotekę ``glob`` (https://docs.python.org/2/library/glob.html) * Wykorzystaj bibliotekę ``glob`` (https://docs.python.org/2/library/glob.html)
* Wyświetl tylko pełną nazwe pliku (wraz z ścieżką). * Wyświetl tylko pełną nazwe pliku (wraz z ścieżką).

3
labs03/task01.py Normal file
View File

@ -0,0 +1,3 @@
print(id([3,5]))
print(id('kot'))
print(id((1/3)))

11
labs03/task02.py Normal file
View File

@ -0,0 +1,11 @@
def Fib(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
for c in Fib(7):
print(c)
##(``F(0)=1, F(1)=1, FN=F(N-1) + F(N-2)``).

5
labs03/task03.py Normal file
View File

@ -0,0 +1,5 @@
# pip install --user requests
import requests
r = requests.get('https://api.fixer.io/latest', auth=('user', 'pass'))
jkursy=r.json()
print("EUR:PLN "+str(jkursy['rates']['PLN']))

20
labs03/task04.py Normal file
View File

@ -0,0 +1,20 @@
#pip install --user weather-api
from datetime import datetime
from weather import Weather
weather=Weather()
city="Poznan"
weather_city=weather.lookup_by_location(city)
print("Aktualna pogoda in "+city+" :", weather_city.condition().text())
def ftoC(t):
return round(5/9 * (t-32),3)
daymap={0:"Poniedziałek",1:"Wtorek",2:"Środa",3:"Czwartek",4:"Piątek",5:"Sobota",6:"Niedziela"}
tmin=[]
dates=[]
for item in weather_city.forecast():
dates.append(item.date())
tmin.append(ftoC(int(item.low())))
print("Minimana temperatura w dniach "+dates[0]+" - " + dates[-1]+ " to " + str(min(tmin)) +"C przewidywana na dzień "+ dates[tmin.index(min(tmin))] + " ("+daymap[datetime.strptime(dates[tmin.index(min(tmin))],'%d %b %Y').weekday()]+").")

8
labs03/task05.py Normal file
View File

@ -0,0 +1,8 @@
import glob,json
bleu={}
name=""
for i in glob.glob('scores/*'):
file=open(i,'r').read().replace(",","").split(" ")
bleu[i]=float(file[2])
print("Maksymalna wartość BLEU znaleziona w pliku: " +max(bleu, key=bleu.get))

View File

@ -309,13 +309,13 @@
{ {
"ename": "AttributeError", "ename": "AttributeError",
"evalue": "'Parser' object has no attribute '__parse'", "evalue": "'Parser' object has no attribute '__parse'",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-80ee186598d3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mParser\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__parse\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-6-80ee186598d3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mParser\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'" "\u001b[0;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'"
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [
@ -465,13 +465,13 @@
{ {
"ename": "FileNotFoundError", "ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'", "evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-20-41928d542bef>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"nieistniejący_plik.txt\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \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[0;32m<ipython-input-20-41928d542bef>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"nieistniejący_plik.txt\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \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[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'" "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'"
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [
@ -614,13 +614,13 @@
{ {
"ename": "MyError", "ename": "MyError",
"evalue": "Coś poszło nie tak!", "evalue": "Coś poszło nie tak!",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mMyError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mMyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-36-4fb306b42ebc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Coś poszło nie tak!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m<ipython-input-36-4fb306b42ebc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Coś poszło nie tak!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mMyError\u001b[0m: Coś poszło nie tak!" "\u001b[0;31mMyError\u001b[0m: Coś poszło nie tak!"
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [

View File

@ -1,3 +1,8 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
def is_numeric(lista):
for x in lista:
if not(isinstance(x,float)) and not(isinstance(x,int)):
return False
return True

View File

@ -1,3 +1,37 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class Employee:
id=0
def __init__(self, imie, nazwisko):
self.imie= imie
self.nazwisko=nazwisko
self.id=id(self)
def get_id(self):
return self.id
class Recruiter(Employee):
recruited=[]
def __init__(self, imie, nazwisko):
super().__init__(imie,nazwisko)
def recruit(self, empId):
self.recruited.append(empId)
class Programmer(Employee):
def __init__(self, imie, nazwisko, rekruter):
super().__init__(imie,nazwisko)
self.recruiter=rekruter.get_id()
prac1=Employee('Anna', 'Nowak')
prac2=Recruiter('Jan', 'Kowalski')
prac3=Programmer('Ala', 'Makota',prac2)
print(prac1.get_id())
print(prac2.get_id())
print(prac3.get_id(), "Zrekrutowany przez ",prac3.recruiter)

View File

@ -1,3 +1,41 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from task01 import *
class DimensionError(Exception):
def __init__(self, text):
self.text = text
def __str__(self):
return self.text
class Point:
def __init__(self, wspolrzedne):
if (is_numeric(wspolrzedne)):
self.wspolrzedne=wspolrzedne
else:
raise Exception("Non numerical coords")
def __len__(self):
return len(self.wspolrzedne)
def __str__(self):
return(str(self.wspolrzedne))
def to_string(self):
return str(self.wspolrzedne)
def __add__(self, other):
if len(self.wspolrzedne)!=len(other.wspolrzedne):
raise DimensionError("Elements have different dimensions!!1")
else:
return [i+j for (i,j) in zip(self.wspolrzedne,other.wspolrzedne)]
pt=Point([1,2])
print(len(pt))
print(str(pt))
print(pt.to_string())
pt2=Point([7,99])
print(pt+pt2)
pt3=Point([1,2,3])
print(pt+pt3)

BIN
labs06/barPlot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,14 +1,18 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pandas as pd
def wczytaj_dane(): def wczytaj_dane():
pass mieszkania = pd.read_csv('mieszkania.csv', # ścieżka do pliku
sep=',', # separator
encoding='UTF-8',
usecols=[0,1,2,3,4,5,6])
return mieszkania
def most_common_room_number(dane): def most_common_room_number(dane):
pass return dane.mode(numeric_only =True)["Rooms"][0]
def cheapest_flats(dane, n): def cheapest_flats(dane, n):
pass return dane.sort_values("Expected")[:n]
def find_borough(desc): def find_borough(desc):
dzielnice = ['Stare Miasto', dzielnice = ['Stare Miasto',
@ -19,36 +23,41 @@ def find_borough(desc):
'Winogrady', 'Winogrady',
'Miłostowo', 'Miłostowo',
'Dębiec'] 'Dębiec']
pass inputList=desc.split(' ')
for i in inputList:
if i in dzielnice:
return i
break
return "Inne"
def add_borough(dane): def add_borough(dane):
pass newcol=dane["Location"].apply(find_borough)
dane["Borough"]=newcol
return dane
def write_plot(dane, filename): def write_plot(dane, filename):
pass bar=dane["Borough"].value_counts().plot(kind="bar", figsize=(6,6))
fig=bar.get_figure()
fig.savefig(filename)
def mean_price(dane, room_number): def mean_price(dane, room_number):
pass return dane[dane["Rooms"]==room_number]["Expected"].mean()
def find_13(dane): def find_13(dane):
pass return dane[dane["Floor"]==13]["Borough"].unique()
def find_best_flats(dane): def find_best_flats(dane):
pass return dane[(dane["Borough"]=="Winogrady") & (dane["Floor"]==1) & (dane["Rooms"]==3)]
def main(): def main():
dane = wczytaj_dane() dane = wczytaj_dane()
print(dane[:5]) print(dane[:5])
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}" print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
.format(most_common_room_number(dane))) .format(most_common_room_number(dane)))
print("{} to najłądniejsza dzielnica w Poznaniu." print("{} to najłądniejsza dzielnica w Poznaniu."
.format(find_borough("Grunwald i Jeżyce")))) .format(find_borough("Grunwald i Jeżyce")))
print("Średnia cena mieszkania 3-pokojowego, to: {}" print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3))) .format(mean_price(dane, 3)))
if __name__ == "__main__": if __name__ == "__main__":
main() main()