forked from tdwojak/Python2017
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0fecba5c4 | |||
26afa652a5 | |||
f61d161938 | |||
5d25e165c4 | |||
dc5fb3f34b | |||
fd67d4b96f | |||
1599eb71ba | |||
524eefe436 | |||
7ef244fb88 | |||
d8025c91ff | |||
378fee7582 | |||
576d5ba943 | |||
c89673937e | |||
e784da982f | |||
4212fd35a1 | |||
2f2b963402 | |||
e222ea8023 | |||
8c76a05200 | |||
f9c3661884 | |||
8231e67c8f | |||
9765333eae | |||
0a345e2101 | |||
feac488751 | |||
ba2d8c7e36 | |||
135d01c0d7 | |||
d311b94e01 | |||
b62e43effe | |||
19c4e498ca |
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# wiki files
|
||||||
|
Python2017.wiki/*
|
||||||
|
|
||||||
|
# Jupyter Files
|
||||||
|
*/.ipynb_checkpoints/*
|
||||||
|
|
||||||
|
# Rope files
|
||||||
|
.ropeproject
|
||||||
|
*/.ropeproject
|
||||||
|
|
||||||
|
# Labs temp files
|
||||||
|
labs03/haslo2.txt
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
|
|
||||||
sumę kodów ASCII znaków.
|
|
||||||
"""
|
|
||||||
def char_sum(text):
|
|
||||||
suma_ascii = 0
|
|
||||||
lista_ascii = []
|
|
||||||
# lista_znaków = list(text)
|
|
||||||
for znak in text:
|
|
||||||
znak_ascii = ord(znak)
|
|
||||||
lista_ascii.append(znak_ascii)
|
|
||||||
for znak2 in lista_ascii:
|
|
||||||
suma_ascii = suma_ascii + znak2
|
|
||||||
return suma_ascii
|
|
||||||
# print('suma ASCII: ', suma_ascii)
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
|
||||||
inputs = [["this is a string"], ["this is another string"]]
|
|
||||||
outputs = [1516, 2172]
|
|
||||||
|
|
||||||
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(char_sum))
|
|
@ -1,31 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
Napisz funkcję sum_div35(n), która zwraca sumę wszystkich liczb podzielnych
|
|
||||||
przez 3 lub 5 mniejszych niż n.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def sum_div35(n):
|
|
||||||
lista_wejsciowa = range(n)
|
|
||||||
lista_wyjsciowa = []
|
|
||||||
suma = 0
|
|
||||||
for i in lista_wejsciowa:
|
|
||||||
if i % 3 == 0 or i % 5 == 0:
|
|
||||||
lista_wyjsciowa.append(i)
|
|
||||||
for j in lista_wyjsciowa:
|
|
||||||
suma = suma + j
|
|
||||||
return suma
|
|
||||||
|
|
||||||
def tests(f):
|
|
||||||
inputs = [[10], [100], [3845]]
|
|
||||||
outputs = [23, 2318, 3446403]
|
|
||||||
|
|
||||||
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(sum_div35))
|
|
@ -1,41 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
Napisz funkcję leet_speak, która podmienia w podanym napisie niektóre litery
|
|
||||||
na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'.
|
|
||||||
Np. leet('leet') powinno zwrócić '1337'.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def leet_speak(text):
|
|
||||||
strin = []
|
|
||||||
for znak in text:
|
|
||||||
if znak == 'e':
|
|
||||||
znak1 = '3'
|
|
||||||
strin.append(znak1)
|
|
||||||
elif znak == 'l':
|
|
||||||
znak1 = '1'
|
|
||||||
strin.append(znak1)
|
|
||||||
elif znak == 'o':
|
|
||||||
znak1 = '0'
|
|
||||||
strin.append(znak1)
|
|
||||||
elif znak == 't':
|
|
||||||
znak1 = '7'
|
|
||||||
strin.append(znak1)
|
|
||||||
else:
|
|
||||||
strin.append(znak)
|
|
||||||
return ''.join(strin)
|
|
||||||
|
|
||||||
def tests(f):
|
|
||||||
inputs = [['leet'], ['do not want']]
|
|
||||||
outputs = ['1337', 'd0 n07 wan7']
|
|
||||||
|
|
||||||
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(leet_speak))
|
|
@ -1,34 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą literę
|
|
||||||
na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def pokemon_speak(text):
|
|
||||||
i = 0
|
|
||||||
new_string = []
|
|
||||||
for j in text:
|
|
||||||
if i % 2 == 0:
|
|
||||||
new_string.append(j.upper())
|
|
||||||
else:
|
|
||||||
new_string.append(j)
|
|
||||||
i = i + 1
|
|
||||||
return ''.join(new_string)
|
|
||||||
|
|
||||||
|
|
||||||
def tests(f):
|
|
||||||
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
|
||||||
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
|
||||||
|
|
||||||
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(pokemon_speak))
|
|
@ -1,42 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie
|
|
||||||
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):
|
|
||||||
output_list1 = []
|
|
||||||
output_list2 = []
|
|
||||||
for j in string1:
|
|
||||||
if j in string2:
|
|
||||||
output_list1.append(j)
|
|
||||||
#print(output_list1)
|
|
||||||
for i in output_list1:
|
|
||||||
if i not in output_list2:
|
|
||||||
output_list2.append(i)
|
|
||||||
for k in output_list2:
|
|
||||||
if k == ' ':
|
|
||||||
output_list2.remove(k)
|
|
||||||
#return output_list2
|
|
||||||
output_list3 = sorted(output_list2)
|
|
||||||
#print(output_list3)
|
|
||||||
return output_list3
|
|
||||||
|
|
||||||
#common_chars("this is a string", "ala ma kota")
|
|
||||||
|
|
||||||
def tests(f):
|
|
||||||
inputs = [["this is a string", "ala ma kota"]]
|
|
||||||
outputs = [['a', 't']]
|
|
||||||
|
|
||||||
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(common_chars))
|
|
124
homeworks/main.py
Executable file
124
homeworks/main.py
Executable file
@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import git
|
||||||
|
import os
|
||||||
|
import importlib
|
||||||
|
import collections
|
||||||
|
import csv
|
||||||
|
|
||||||
|
logger = logging.getLogger('Homeworks')
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
fm = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(fm)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
|
||||||
|
def arg_parse():
|
||||||
|
parser = argparse.ArgumentParser(description='Framework for checking homeworks.')
|
||||||
|
parser.add_argument('-i', '--ids', type=str,
|
||||||
|
help='path to a file with student ids.')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def get_ids(path):
|
||||||
|
ids = []
|
||||||
|
with open(path) as _file:
|
||||||
|
for line in _file:
|
||||||
|
ids.append(line.strip().split(' ')[::2])
|
||||||
|
return ids
|
||||||
|
|
||||||
|
|
||||||
|
def clone_repo(username, repo_name):
|
||||||
|
repo = "https://git.wmi.amu.edu.pl/{}/{}.git".format(username, repo_name)
|
||||||
|
dest = "./Python2017-{}".format(username)
|
||||||
|
if os.path.exists(dest):
|
||||||
|
logger.debug("{}: repo exests.".format(username))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
git.Repo.clone_from(repo, dest)
|
||||||
|
except git.GitCommandError:
|
||||||
|
logger.info("Repository '{}' does not exist".format(repo))
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def check_tasks(username, repo_name, tasks):
|
||||||
|
logger.debug("Marking user: {}".format(username))
|
||||||
|
scores = collections.defaultdict(dict)
|
||||||
|
for lab in tasks:
|
||||||
|
path = os.path.realpath("./Python2017-{}/{}".format(username, lab))
|
||||||
|
for task, fun in tasks[lab]:
|
||||||
|
task_file = path + "/{}". format(task)
|
||||||
|
logger.debug(task_file)
|
||||||
|
package = 'Python2017-{}.{}.{}'.format(username, lab, task)
|
||||||
|
lib = importlib.import_module(package)
|
||||||
|
tested_fun = getattr(lib, fun)
|
||||||
|
tests = getattr(lib, 'tests')
|
||||||
|
try:
|
||||||
|
test_result = tests(tested_fun)
|
||||||
|
except Exception:
|
||||||
|
test_result = "FAILED"
|
||||||
|
|
||||||
|
if test_result == 'TESTS PASSED':
|
||||||
|
scores[lab][task] = 1
|
||||||
|
else:
|
||||||
|
scores[lab][task] = 0
|
||||||
|
return scores
|
||||||
|
|
||||||
|
def get_fieldnames(tasks):
|
||||||
|
fieldnames = ['ID']
|
||||||
|
for lab in tasks:
|
||||||
|
for task, _ in tasks[lab]:
|
||||||
|
fieldnames.append('{}:{}'.format(lab, task))
|
||||||
|
return fieldnames
|
||||||
|
|
||||||
|
def parse_scores(fieldnames, uname, scores):
|
||||||
|
out = {}
|
||||||
|
for name in fieldnames:
|
||||||
|
if name == 'ID':
|
||||||
|
out[name] = uname
|
||||||
|
continue
|
||||||
|
lab, task = name.split(':')
|
||||||
|
out[name] = scores[lab][task]
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def write_scores(scores, filename, tasks):
|
||||||
|
fieldnames = get_fieldnames(tasks)
|
||||||
|
|
||||||
|
with open(filename, 'w') as results:
|
||||||
|
writer = csv.DictWriter(results, fieldnames, restval=0)
|
||||||
|
writer.writeheader()
|
||||||
|
for student in scores:
|
||||||
|
writer.writerow(parse_scores(fieldnames, student, scores[student]))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
""" main """
|
||||||
|
options = arg_parse()
|
||||||
|
ids = get_ids(options.ids)
|
||||||
|
logger.info("Liczba studentów: {}".format(len(ids)))
|
||||||
|
scores = {}
|
||||||
|
|
||||||
|
tasks = {
|
||||||
|
'labs02' : [
|
||||||
|
('task07', 'char_sum'),
|
||||||
|
('task08', 'sum_div35'),
|
||||||
|
('task09', 'leet_speak'),
|
||||||
|
('task10', 'pokemon_speak'),
|
||||||
|
('task11', 'common_chars')
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
for repo_id in ids:
|
||||||
|
st_uname = repo_id[0]
|
||||||
|
repo_name = repo_id[-1]
|
||||||
|
if clone_repo(st_uname, repo_name):
|
||||||
|
scores[st_uname] = check_tasks(st_uname, repo_name, tasks)
|
||||||
|
write_scores(scores, 'results.csv', tasks)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
38
homeworks/results.md
Normal file
38
homeworks/results.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
ID | labs02:task07 | labs02:task08 | labs02:task09 | labs02:task10 | labs02:task11 | labs03 | labs04 | labs06 | Punkty | Ocena |
|
||||||
|
---------|-----------------|-----------------|-----------------|-----------------|-----------------|----------|----------|----------|--------|-------|
|
||||||
|
s45146 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45147 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45148 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45150 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 8 | 16 | 4 |
|
||||||
|
s45151 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 18 | 4.5 |
|
||||||
|
s45152 | 1 | 1 | 1 | 0 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||||
|
s45153 | 0 | 1 | 1 | 1 | 1 | 4 | 0 | 8 | 16 | 4 |
|
||||||
|
s45155 | 1 | 1 | 1 | 1 | 1 | 1 | 5 | 8 | 19 | 4.5 |
|
||||||
|
s45156 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45157 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
|
s45158 | 1 | 1 | 0 | 0 | 1 | 4 | 5 | 8 | 19 | 4.5 |
|
||||||
|
s45159 | 1 | 1 | 1 | 1 | 1 | 2 | 3 | 8 | 18 | 4.5 |
|
||||||
|
s45160 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
|
s45161 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45162 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45163 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
|
s45164 | 1 | 1 | 0 | 1 | 0 | 0 | 5 | 8 | 16 | 4 |
|
||||||
|
s45165 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45166 | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 8 | 22 | 5 |
|
||||||
|
s45167 | 1 | 1 | 1 | 1 | 1 | 0 | 5 | 8 | 17 | 4 |
|
||||||
|
s45168 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
|
||||||
|
s45452 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | 8 | 21 | 5 |
|
||||||
|
szwedek | 1 | 1 | 1 | 1 | 1 | 4 | 5 | 10 | 24 | 5 |
|
||||||
|
|
||||||
|
Skala:
|
||||||
|
|
||||||
|
Punkty | Ocena |
|
||||||
|
-------|-------|
|
||||||
|
24-20 | 5 |
|
||||||
|
19-18 | 4.5 |
|
||||||
|
17-16 | 4 |
|
||||||
|
15-13 | 3 |
|
||||||
|
12-0 | 2 |
|
||||||
|
|
||||||
|
|
||||||
|
Max: 22
|
@ -8,7 +8,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
|||||||
|
|
||||||
def even_elements(lista):
|
def even_elements(lista):
|
||||||
pass
|
pass
|
||||||
return lista[::2]
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
||||||
|
@ -5,14 +5,8 @@
|
|||||||
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def days_in_year(year):
|
def days_in_year(days):
|
||||||
pass
|
pass
|
||||||
if year % 400 == 0:
|
|
||||||
return 366
|
|
||||||
elif year % 4 == 0 and year % 100 != 0:
|
|
||||||
return 366
|
|
||||||
else:
|
|
||||||
return 365
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||||
|
@ -11,18 +11,12 @@ 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ń.)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
text = "this is a string , which i will use for string testing"
|
|
||||||
vocab = [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i']
|
|
||||||
|
|
||||||
def oov(text, vocab):
|
def oov(text, vocab):
|
||||||
pass
|
pass
|
||||||
temp_text=text.split(' ')
|
|
||||||
temp_vocab=vocab.split(' ')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [("this is a string , which i will use for string testing",
|
inputs = [("this is a string , which i will use for string testing",
|
||||||
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
|
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
|
||||||
@ -36,4 +30,3 @@ def tests(f):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(tests(oov))
|
print(tests(oov))
|
||||||
"""
|
|
@ -13,7 +13,7 @@ def pokemon_speak(text):
|
|||||||
|
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
inputs = [['pokemon'], ['do not want'], 'POKEMON']
|
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
||||||
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
||||||
|
|
||||||
for input, output in zip(inputs, outputs):
|
for input, output in zip(inputs, outputs):
|
||||||
|
@ -6,7 +6,6 @@ def suma(a, b):
|
|||||||
"""
|
"""
|
||||||
Napisz funkcję, która zwraca sumę elementów.
|
Napisz funkcję, która zwraca sumę elementów.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
return a + b
|
return a + b
|
||||||
|
|
||||||
def tests(f):
|
def tests(f):
|
||||||
@ -19,5 +18,4 @@ def tests(f):
|
|||||||
break
|
break
|
||||||
return "TESTS PASSED"
|
return "TESTS PASSED"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(tests(suma))
|
print(tests(suma))
|
||||||
|
630
labs03/Podstawy 2.ipynb
Normal file
630
labs03/Podstawy 2.ipynb
Normal file
@ -0,0 +1,630 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# Python: podstaw ciąg dalszy\n",
|
||||||
|
"\n",
|
||||||
|
"## Tomasz Dwojak\n",
|
||||||
|
"\n",
|
||||||
|
"### 2 grudnia 2017"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Co już znamy?\n",
|
||||||
|
" * podstawowe typy danych i operacje na nich\n",
|
||||||
|
" * Instrukcje sterujące: ``if``, ``for``\n",
|
||||||
|
" * pisanie funkcji\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Co na dziś?\n",
|
||||||
|
"\n",
|
||||||
|
" * ``tuple`` i ``set``,\n",
|
||||||
|
" * operacje na plikach,\n",
|
||||||
|
" * coś więcej o funkcjach\n",
|
||||||
|
" * korzystanie z bibliotek\n",
|
||||||
|
" * przegląd najważniejszych bibliotek"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 9,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"2\n",
|
||||||
|
"[1, 2, 3, 1, 2, 3]\n",
|
||||||
|
"123\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"def dwojak(x): \n",
|
||||||
|
" x *= 2\n",
|
||||||
|
" return x\n",
|
||||||
|
" \n",
|
||||||
|
"l = [1, 2, 3]\n",
|
||||||
|
"s = \"123\"\n",
|
||||||
|
"\n",
|
||||||
|
"dwojak(l)\n",
|
||||||
|
"dwojak(s)\n",
|
||||||
|
"print(dwojak(1))\n",
|
||||||
|
"print(l)\n",
|
||||||
|
"print(s)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Mutable i Immutable\n",
|
||||||
|
"\n",
|
||||||
|
"### Mutable\n",
|
||||||
|
" * listy,\n",
|
||||||
|
" * słowniki,\n",
|
||||||
|
" * sety,\n",
|
||||||
|
" * własnoręcznie zdefiniowane klasy.\n",
|
||||||
|
" \n",
|
||||||
|
"### Immutable\n",
|
||||||
|
" * liczby: inty i floaty,\n",
|
||||||
|
" * napisy,\n",
|
||||||
|
" * tuple."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Nieoczywistości"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 11,
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"def dwojak1(x): x *= 2\n",
|
||||||
|
"def dwojak2(x): \n",
|
||||||
|
" x = x * 2\n",
|
||||||
|
" print(\"F:\", x)\n",
|
||||||
|
"\n",
|
||||||
|
"l = [1,2, 3]\n",
|
||||||
|
"dwojak1(l)\n",
|
||||||
|
"print(l)\n",
|
||||||
|
"\n",
|
||||||
|
"l = [1,2, 3]\n",
|
||||||
|
"dwojak2(l)\n",
|
||||||
|
"print(l)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[1, 2, 3]\n",
|
||||||
|
"[1, 2, 3, 4]\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"l = [1, 2, 3]\n",
|
||||||
|
"e = l[:]\n",
|
||||||
|
"e.append(4)\n",
|
||||||
|
"print(l)\n",
|
||||||
|
"print(e)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[[1], [1], [1]]\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"e = []\n",
|
||||||
|
"f = [e for i in range(3)]\n",
|
||||||
|
"f[0].append(1)\n",
|
||||||
|
"print(f)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## To może ``tuple``?\n",
|
||||||
|
" * stały rozmiar,\n",
|
||||||
|
" * immutable,\n",
|
||||||
|
" * mogą być kluczami w słownikach"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 25,
|
||||||
|
"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'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"t = (1, \"napis\", [])\n",
|
||||||
|
"t[-1].append(0)\n",
|
||||||
|
"print(t)\n",
|
||||||
|
"print(len(t))\n",
|
||||||
|
"print({t: None})"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Funkcje cz. 2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 36,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"15\n",
|
||||||
|
"a == 1\n",
|
||||||
|
"b == (3, 4)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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",
|
||||||
|
" if kwargs is not None:\n",
|
||||||
|
" for key, value in kwargs.items():\n",
|
||||||
|
" print(\"%s == %s\" %(key,value))\n",
|
||||||
|
"greet_me(a=1, b=(3,4))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Generatory"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 38,
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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",
|
||||||
|
" print(c)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Operacje na plikach"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 45,
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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,
|
||||||
|
"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."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"with open(\"haslo.txt\", 'r') as plik:\n",
|
||||||
|
" for linia in plik.readlines():\n",
|
||||||
|
" print(linia)\n",
|
||||||
|
"print(plik.read())"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 48,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"with open(\"haslo2.txt\", 'w') as plik:\n",
|
||||||
|
" for word in ('corect', 'horse', 'battery', 'staple'):\n",
|
||||||
|
" plik.write(word)\n",
|
||||||
|
" plik.write('\\n')\n",
|
||||||
|
"with open(\"haslo2.txt\", 'w+') as plik:\n",
|
||||||
|
" plik.writelines([' '.join(('corect', 'horse', 'battery', 'staple'))])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# Korzystanie z modułów"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Importowanie"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 49,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"posix\n",
|
||||||
|
"Nazwa uzytkownika: tomaszd\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import os\n",
|
||||||
|
"print(os.name)\n",
|
||||||
|
"\n",
|
||||||
|
"from os import getenv\n",
|
||||||
|
"print('Nazwa uzytkownika: {}'.format(getenv(\"USER\")))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 50,
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from collections import *\n",
|
||||||
|
"print(Counter(\"konstantynopolitańczykowianeczka\"))\n",
|
||||||
|
"\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"np.array([[1, 3, 4, 5]], dtype='float32')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Instalacja\n",
|
||||||
|
"\n",
|
||||||
|
" * lokalnie (per użytkownik) lub globalnie\n",
|
||||||
|
" * pyCharm lub linia komend, np. ``pip install --user flask`` lub ``python -m pip install --user flask``"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Wczytywanie z klawiatury"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 51,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"What's your name?\n",
|
||||||
|
"Tomasz\n",
|
||||||
|
"Welcome home, Tomasz.\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"name = input(\"What's your name?\\n\")\n",
|
||||||
|
"print(\"Welcome home, {}.\".format(name))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"liczby = eval(input(\"Podaj liczby\"))\n",
|
||||||
|
"print(sum(liczby))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Co ominąłem?\n",
|
||||||
|
"\n",
|
||||||
|
" * klasy (jutro)\n",
|
||||||
|
" * podział programu na pliki (jutro)\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"celltoolbar": "Slideshow",
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.6.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
36
labs03/README.md
Normal file
36
labs03/README.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Laboratoria 3
|
||||||
|
|
||||||
|
## Zadania
|
||||||
|
|
||||||
|
**ćwiczenie 0**
|
||||||
|
Sklonuj repozytorium ``https://github.com/realpython/python-scripts``, które różne, przydatne skrypty. Przejrzyj je i zobacz na ile jesteś w stanie zrozumieć co i jak robią. Uruchom kilka z nich, np. ``27_send_sms.py``.
|
||||||
|
|
||||||
|
**ć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.
|
||||||
|
|
||||||
|
**ć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)``).
|
||||||
|
|
||||||
|
**ćwiczenie 3**
|
||||||
|
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.
|
||||||
|
|
||||||
|
**ćwiczenie 4**
|
||||||
|
Zainstaluj bibliotekę ``weather-api`` (https://pypi.python.org/pypi/weather-api). Korzystając z niej:
|
||||||
|
* Wypisz informacje o aktualnej pogodzie.
|
||||||
|
* Napisz funkcję, która zamieni stopnie ``F`` na ``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**
|
||||||
|
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)
|
||||||
|
* Wyświetl tylko pełną nazwe pliku (wraz z ścieżką).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
2
labs03/haslo.txt
Normal file
2
labs03/haslo.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
W Paryżu najlepsze kasztany są na placu Pigalle
|
||||||
|
Zuzanna lubi je tylko jesienią.
|
1
labs03/scores/model.iter10000.npz.bleu
Normal file
1
labs03/scores/model.iter10000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 2.02, 17.1/3.6/1.0/0.3 (BP=1.000, ratio=1.872, hyp_len=80326, ref_len=42903)
|
1
labs03/scores/model.iter100000.npz.bleu
Normal file
1
labs03/scores/model.iter100000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 13.99, 44.4/18.5/9.3/5.0 (BP=1.000, ratio=1.072, hyp_len=45976, ref_len=42903)
|
1
labs03/scores/model.iter110000.npz.bleu
Normal file
1
labs03/scores/model.iter110000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 14.35, 44.9/19.0/9.6/5.2 (BP=1.000, ratio=1.087, hyp_len=46657, ref_len=42903)
|
1
labs03/scores/model.iter120000.npz.bleu
Normal file
1
labs03/scores/model.iter120000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.75, 47.1/20.5/10.7/6.0 (BP=1.000, ratio=1.030, hyp_len=44211, ref_len=42903)
|
1
labs03/scores/model.iter130000.npz.bleu
Normal file
1
labs03/scores/model.iter130000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.96, 47.7/20.8/10.9/6.0 (BP=1.000, ratio=1.029, hyp_len=44160, ref_len=42903)
|
1
labs03/scores/model.iter140000.npz.bleu
Normal file
1
labs03/scores/model.iter140000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.42, 46.8/20.3/10.5/5.7 (BP=1.000, ratio=1.043, hyp_len=44729, ref_len=42903)
|
1
labs03/scores/model.iter150000.npz.bleu
Normal file
1
labs03/scores/model.iter150000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.84, 47.3/20.7/10.8/5.9 (BP=1.000, ratio=1.034, hyp_len=44374, ref_len=42903)
|
1
labs03/scores/model.iter160000.npz.bleu
Normal file
1
labs03/scores/model.iter160000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.99, 47.7/20.8/10.9/6.0 (BP=1.000, ratio=1.031, hyp_len=44233, ref_len=42903)
|
1
labs03/scores/model.iter170000.npz.bleu
Normal file
1
labs03/scores/model.iter170000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.15, 47.9/21.0/11.0/6.1 (BP=1.000, ratio=1.027, hyp_len=44065, ref_len=42903)
|
1
labs03/scores/model.iter180000.npz.bleu
Normal file
1
labs03/scores/model.iter180000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 15.86, 47.1/20.8/10.8/6.0 (BP=1.000, ratio=1.053, hyp_len=45191, ref_len=42903)
|
1
labs03/scores/model.iter190000.npz.bleu
Normal file
1
labs03/scores/model.iter190000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.07, 47.7/21.0/11.0/6.0 (BP=1.000, ratio=1.044, hyp_len=44795, ref_len=42903)
|
1
labs03/scores/model.iter20000.npz.bleu
Normal file
1
labs03/scores/model.iter20000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 5.87, 31.1/8.9/3.3/1.3 (BP=1.000, ratio=1.155, hyp_len=49533, ref_len=42903)
|
1
labs03/scores/model.iter200000.npz.bleu
Normal file
1
labs03/scores/model.iter200000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.82, 48.9/21.7/11.5/6.6 (BP=0.998, ratio=0.998, hyp_len=42837, ref_len=42903)
|
1
labs03/scores/model.iter210000.npz.bleu
Normal file
1
labs03/scores/model.iter210000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.70, 48.7/21.7/11.5/6.4 (BP=1.000, ratio=1.017, hyp_len=43622, ref_len=42903)
|
1
labs03/scores/model.iter220000.npz.bleu
Normal file
1
labs03/scores/model.iter220000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.85, 48.9/21.9/11.7/6.5 (BP=1.000, ratio=1.020, hyp_len=43777, ref_len=42903)
|
1
labs03/scores/model.iter230000.npz.bleu
Normal file
1
labs03/scores/model.iter230000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.59, 48.3/21.6/11.4/6.3 (BP=1.000, ratio=1.029, hyp_len=44127, ref_len=42903)
|
1
labs03/scores/model.iter240000.npz.bleu
Normal file
1
labs03/scores/model.iter240000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.94, 48.6/22.0/11.7/6.6 (BP=1.000, ratio=1.038, hyp_len=44517, ref_len=42903)
|
1
labs03/scores/model.iter250000.npz.bleu
Normal file
1
labs03/scores/model.iter250000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.52, 49.7/22.5/12.2/6.9 (BP=1.000, ratio=1.003, hyp_len=43053, ref_len=42903)
|
1
labs03/scores/model.iter260000.npz.bleu
Normal file
1
labs03/scores/model.iter260000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.82, 48.6/21.9/11.6/6.5 (BP=1.000, ratio=1.037, hyp_len=44475, ref_len=42903)
|
1
labs03/scores/model.iter270000.npz.bleu
Normal file
1
labs03/scores/model.iter270000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.16, 49.2/22.3/11.9/6.6 (BP=1.000, ratio=1.025, hyp_len=43965, ref_len=42903)
|
1
labs03/scores/model.iter280000.npz.bleu
Normal file
1
labs03/scores/model.iter280000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.92, 49.4/22.1/11.7/6.4 (BP=1.000, ratio=1.013, hyp_len=43453, ref_len=42903)
|
1
labs03/scores/model.iter290000.npz.bleu
Normal file
1
labs03/scores/model.iter290000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.20, 49.2/22.1/11.9/6.8 (BP=1.000, ratio=1.016, hyp_len=43578, ref_len=42903)
|
1
labs03/scores/model.iter30000.npz.bleu
Normal file
1
labs03/scores/model.iter30000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 8.17, 33.9/11.6/5.0/2.3 (BP=1.000, ratio=1.207, hyp_len=51768, ref_len=42903)
|
1
labs03/scores/model.iter300000.npz.bleu
Normal file
1
labs03/scores/model.iter300000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.31, 49.2/22.2/12.0/6.8 (BP=1.000, ratio=1.017, hyp_len=43642, ref_len=42903)
|
1
labs03/scores/model.iter310000.npz.bleu
Normal file
1
labs03/scores/model.iter310000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.57, 49.5/22.5/12.3/7.0 (BP=1.000, ratio=1.000, hyp_len=42900, ref_len=42903)
|
1
labs03/scores/model.iter320000.npz.bleu
Normal file
1
labs03/scores/model.iter320000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.68, 49.6/22.6/12.3/7.1 (BP=1.000, ratio=1.013, hyp_len=43465, ref_len=42903)
|
1
labs03/scores/model.iter330000.npz.bleu
Normal file
1
labs03/scores/model.iter330000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.02, 48.3/21.9/11.8/6.7 (BP=1.000, ratio=1.044, hyp_len=44801, ref_len=42903)
|
1
labs03/scores/model.iter340000.npz.bleu
Normal file
1
labs03/scores/model.iter340000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.51, 49.7/22.7/12.2/6.9 (BP=1.000, ratio=1.011, hyp_len=43368, ref_len=42903)
|
1
labs03/scores/model.iter350000.npz.bleu
Normal file
1
labs03/scores/model.iter350000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.68, 50.3/22.9/12.4/7.0 (BP=0.995, ratio=0.995, hyp_len=42702, ref_len=42903)
|
1
labs03/scores/model.iter360000.npz.bleu
Normal file
1
labs03/scores/model.iter360000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.43, 49.0/22.4/12.2/6.9 (BP=1.000, ratio=1.040, hyp_len=44629, ref_len=42903)
|
1
labs03/scores/model.iter370000.npz.bleu
Normal file
1
labs03/scores/model.iter370000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.16, 49.2/22.2/11.9/6.7 (BP=1.000, ratio=1.028, hyp_len=44085, ref_len=42903)
|
1
labs03/scores/model.iter380000.npz.bleu
Normal file
1
labs03/scores/model.iter380000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.04, 49.1/22.2/11.8/6.6 (BP=1.000, ratio=1.030, hyp_len=44200, ref_len=42903)
|
1
labs03/scores/model.iter390000.npz.bleu
Normal file
1
labs03/scores/model.iter390000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.77, 49.8/22.8/12.4/7.1 (BP=1.000, ratio=1.008, hyp_len=43258, ref_len=42903)
|
1
labs03/scores/model.iter40000.npz.bleu
Normal file
1
labs03/scores/model.iter40000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 8.55, 32.5/11.9/5.3/2.6 (BP=1.000, ratio=1.341, hyp_len=57542, ref_len=42903)
|
1
labs03/scores/model.iter400000.npz.bleu
Normal file
1
labs03/scores/model.iter400000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.96, 50.0/23.0/12.6/7.2 (BP=1.000, ratio=1.002, hyp_len=43009, ref_len=42903)
|
1
labs03/scores/model.iter410000.npz.bleu
Normal file
1
labs03/scores/model.iter410000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.66, 49.6/22.6/12.3/7.0 (BP=1.000, ratio=1.019, hyp_len=43697, ref_len=42903)
|
1
labs03/scores/model.iter420000.npz.bleu
Normal file
1
labs03/scores/model.iter420000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.93, 49.8/23.1/12.6/7.2 (BP=1.000, ratio=1.021, hyp_len=43824, ref_len=42903)
|
1
labs03/scores/model.iter430000.npz.bleu
Normal file
1
labs03/scores/model.iter430000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 16.55, 47.0/21.3/11.5/6.5 (BP=1.000, ratio=1.071, hyp_len=45947, ref_len=42903)
|
1
labs03/scores/model.iter440000.npz.bleu
Normal file
1
labs03/scores/model.iter440000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.59, 49.8/22.7/12.2/6.9 (BP=1.000, ratio=1.009, hyp_len=43301, ref_len=42903)
|
1
labs03/scores/model.iter450000.npz.bleu
Normal file
1
labs03/scores/model.iter450000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.41, 49.2/22.5/12.1/6.9 (BP=1.000, ratio=1.023, hyp_len=43894, ref_len=42903)
|
1
labs03/scores/model.iter460000.npz.bleu
Normal file
1
labs03/scores/model.iter460000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.52, 49.9/22.7/12.2/6.8 (BP=1.000, ratio=1.005, hyp_len=43127, ref_len=42903)
|
1
labs03/scores/model.iter470000.npz.bleu
Normal file
1
labs03/scores/model.iter470000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.30, 49.1/22.3/12.0/6.8 (BP=1.000, ratio=1.024, hyp_len=43917, ref_len=42903)
|
1
labs03/scores/model.iter480000.npz.bleu
Normal file
1
labs03/scores/model.iter480000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.21, 48.8/22.1/12.0/6.8 (BP=1.000, ratio=1.036, hyp_len=44454, ref_len=42903)
|
1
labs03/scores/model.iter490000.npz.bleu
Normal file
1
labs03/scores/model.iter490000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.79, 50.0/22.9/12.4/7.1 (BP=1.000, ratio=1.000, hyp_len=42891, ref_len=42903)
|
1
labs03/scores/model.iter50000.npz.bleu
Normal file
1
labs03/scores/model.iter50000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 11.03, 39.5/15.1/7.1/3.5 (BP=1.000, ratio=1.116, hyp_len=47860, ref_len=42903)
|
1
labs03/scores/model.iter500000.npz.bleu
Normal file
1
labs03/scores/model.iter500000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.25, 49.4/22.3/12.0/6.7 (BP=1.000, ratio=1.014, hyp_len=43517, ref_len=42903)
|
1
labs03/scores/model.iter510000.npz.bleu
Normal file
1
labs03/scores/model.iter510000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.78, 50.0/22.8/12.4/7.1 (BP=1.000, ratio=1.000, hyp_len=42890, ref_len=42903)
|
1
labs03/scores/model.iter520000.npz.bleu
Normal file
1
labs03/scores/model.iter520000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.68, 49.8/22.7/12.4/7.0 (BP=1.000, ratio=1.003, hyp_len=43021, ref_len=42903)
|
1
labs03/scores/model.iter530000.npz.bleu
Normal file
1
labs03/scores/model.iter530000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.31, 48.9/22.3/12.1/6.8 (BP=1.000, ratio=1.032, hyp_len=44262, ref_len=42903)
|
1
labs03/scores/model.iter540000.npz.bleu
Normal file
1
labs03/scores/model.iter540000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.92, 49.8/22.9/12.5/7.2 (BP=1.000, ratio=1.015, hyp_len=43562, ref_len=42903)
|
1
labs03/scores/model.iter550000.npz.bleu
Normal file
1
labs03/scores/model.iter550000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.84, 50.0/22.9/12.5/7.1 (BP=1.000, ratio=1.011, hyp_len=43389, ref_len=42903)
|
1
labs03/scores/model.iter560000.npz.bleu
Normal file
1
labs03/scores/model.iter560000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.75, 49.8/22.8/12.4/7.1 (BP=1.000, ratio=1.014, hyp_len=43494, ref_len=42903)
|
1
labs03/scores/model.iter570000.npz.bleu
Normal file
1
labs03/scores/model.iter570000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.94, 50.0/23.1/12.6/7.1 (BP=1.000, ratio=1.013, hyp_len=43442, ref_len=42903)
|
1
labs03/scores/model.iter580000.npz.bleu
Normal file
1
labs03/scores/model.iter580000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 18.12, 50.3/23.1/12.7/7.3 (BP=1.000, ratio=1.004, hyp_len=43077, ref_len=42903)
|
1
labs03/scores/model.iter590000.npz.bleu
Normal file
1
labs03/scores/model.iter590000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.29, 48.8/22.3/12.1/6.8 (BP=1.000, ratio=1.042, hyp_len=44688, ref_len=42903)
|
1
labs03/scores/model.iter60000.npz.bleu
Normal file
1
labs03/scores/model.iter60000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 11.92, 40.2/16.1/7.8/4.0 (BP=1.000, ratio=1.144, hyp_len=49071, ref_len=42903)
|
1
labs03/scores/model.iter600000.npz.bleu
Normal file
1
labs03/scores/model.iter600000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.46, 49.5/22.5/12.2/6.8 (BP=1.000, ratio=1.026, hyp_len=44035, ref_len=42903)
|
1
labs03/scores/model.iter610000.npz.bleu
Normal file
1
labs03/scores/model.iter610000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 18.19, 50.3/23.2/12.7/7.4 (BP=1.000, ratio=1.007, hyp_len=43221, ref_len=42903)
|
1
labs03/scores/model.iter620000.npz.bleu
Normal file
1
labs03/scores/model.iter620000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 17.84, 50.1/22.9/12.5/7.1 (BP=1.000, ratio=1.016, hyp_len=43604, ref_len=42903)
|
1
labs03/scores/model.iter630000.npz.bleu
Normal file
1
labs03/scores/model.iter630000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 18.30, 50.8/23.4/12.9/7.5 (BP=0.994, ratio=0.994, hyp_len=42632, ref_len=42903)
|
1
labs03/scores/model.iter640000.npz.bleu
Normal file
1
labs03/scores/model.iter640000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 0, 0/0/0/0 (BP=0, ratio=0, hyp_len=0, ref_len=0)
|
1
labs03/scores/model.iter70000.npz.bleu
Normal file
1
labs03/scores/model.iter70000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 12.77, 42.4/17.1/8.4/4.4 (BP=1.000, ratio=1.096, hyp_len=47008, ref_len=42903)
|
1
labs03/scores/model.iter80000.npz.bleu
Normal file
1
labs03/scores/model.iter80000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 14.43, 46.7/19.4/9.7/5.2 (BP=0.988, ratio=0.988, hyp_len=42376, ref_len=42903)
|
1
labs03/scores/model.iter90000.npz.bleu
Normal file
1
labs03/scores/model.iter90000.npz.bleu
Normal file
@ -0,0 +1 @@
|
|||||||
|
BLEU = 13.85, 44.1/18.5/9.2/4.9 (BP=1.000, ratio=1.092, hyp_len=46859, ref_len=42903)
|
662
labs04/Klasy.ipynb
Normal file
662
labs04/Klasy.ipynb
Normal file
@ -0,0 +1,662 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# Wprowadzenie do Pythona: Klasy\n",
|
||||||
|
"\n",
|
||||||
|
"## Tomasz Dwojak\n",
|
||||||
|
"\n",
|
||||||
|
"### 3 grudnia 2017"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"# Plan na dziś:\n",
|
||||||
|
" * klasy,\n",
|
||||||
|
" * wyjątki."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Python jest językiem obiektowym \n",
|
||||||
|
" * Wszystko jest obiektem: liczby, napisy, None, funkcje, moduły (biblioteki)..."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 11,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"0\n",
|
||||||
|
"Python da się lubić !\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"print((2017).imag)\n",
|
||||||
|
"print(' '.join(['Python', 'da', 'się', 'lubić', '!']))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Konstrukcja"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 18,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"<class '__main__.NajprostszaKlasa'>\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class NajprostszaKlasa:\n",
|
||||||
|
" pass\n",
|
||||||
|
"\n",
|
||||||
|
"nasza_klasa = NajprostszaKlasa() # Uwaga na nawiasy na końcu!\n",
|
||||||
|
"print(type(nasza_klasa))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## (Pseudo) Konstruktor \n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 30,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"2\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Punkt:\n",
|
||||||
|
" def __init__(self, x, y):\n",
|
||||||
|
" self.x = x\n",
|
||||||
|
" self.y = y\n",
|
||||||
|
"\n",
|
||||||
|
"punkt = Punkt(2, 3)\n",
|
||||||
|
"print(punkt.x)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 25,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"class Figura:\n",
|
||||||
|
" def __init__(self, vertexes):\n",
|
||||||
|
" self.vertexes = vertexes\n",
|
||||||
|
" \n",
|
||||||
|
" def liczba_wierzcholkow(self):\n",
|
||||||
|
" return len(self.vertexes)\n",
|
||||||
|
" \n",
|
||||||
|
" def dodaj_wierzcholek(self, x):\n",
|
||||||
|
" self.vertexes.append(x)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 26,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"class Prostokat(Figura):\n",
|
||||||
|
" def __init__(self, vertexes):\n",
|
||||||
|
" super().__init__(vertexes)\n",
|
||||||
|
" \n",
|
||||||
|
" def czy_jestem_kwadratem(self):\n",
|
||||||
|
" pass\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 28,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"3"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 28,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Figura:\n",
|
||||||
|
" def __init__(self, vertexes):\n",
|
||||||
|
" self.vertexes = vertexes\n",
|
||||||
|
" \n",
|
||||||
|
" def liczba_wierzcholkow(self):\n",
|
||||||
|
" return len(self.vertexes)\n",
|
||||||
|
" \n",
|
||||||
|
" def __len__(self):\n",
|
||||||
|
" return self.liczba_wierzcholkow()\n",
|
||||||
|
" \n",
|
||||||
|
"len(Figura([Punkt(2,3), Punkt(3,4), Punkt(0, 0)]))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Dobre praktyki: komentarze"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"class Punkt(object):\n",
|
||||||
|
" \"\"\"Klasa reprezentująca punkt w 2D.\"\"\"\n",
|
||||||
|
" def __init__(self, x, y):\n",
|
||||||
|
" \"\"\"opis argumentów x i y.\"\"\"\n",
|
||||||
|
" self.x = x\n",
|
||||||
|
" self.y = y"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Help on class Punkt in module __main__:\n",
|
||||||
|
"\n",
|
||||||
|
"class Punkt(builtins.object)\n",
|
||||||
|
" | Klasa reprezentująca punkt w 2D.\n",
|
||||||
|
" | \n",
|
||||||
|
" | Methods defined here:\n",
|
||||||
|
" | \n",
|
||||||
|
" | __init__(self, x, y)\n",
|
||||||
|
" | opis argumentów x i y.\n",
|
||||||
|
" | \n",
|
||||||
|
" | ----------------------------------------------------------------------\n",
|
||||||
|
" | Data descriptors defined here:\n",
|
||||||
|
" | \n",
|
||||||
|
" | __dict__\n",
|
||||||
|
" | dictionary for instance variables (if defined)\n",
|
||||||
|
" | \n",
|
||||||
|
" | __weakref__\n",
|
||||||
|
" | list of weak references to the object (if defined)\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"help(Punkt)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Enkapsulacja: publiczne czy prywatne?\n",
|
||||||
|
" * Prywatne zaczynają się od dwóch podkreśleń: ``__``, np. ``def __policz(self)``\n",
|
||||||
|
" * chronione tylko w konwencji, zaczynają się od '\\_', np. ``def _parse(self)``\n",
|
||||||
|
" * publiczne jest wszystko co nie zaczyna się od '\\_'."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "AttributeError",
|
||||||
|
"evalue": "'Parser' object has no attribute '__parse'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\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;31mAttributeError\u001b[0m: 'Parser' object has no attribute '__parse'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Parser(object):\n",
|
||||||
|
" def __parse(self): pass\n",
|
||||||
|
" def _get(self): pass\n",
|
||||||
|
"parser = Parser()\n",
|
||||||
|
"parser._get()\n",
|
||||||
|
"parser.__parse()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Iteratory"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"<__main__.Punkt object at 0x7f728015b358>\n",
|
||||||
|
"<__main__.Punkt object at 0x7f728015b4a8>\n",
|
||||||
|
"<__main__.Punkt object at 0x7f728015b438>\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Figura:\n",
|
||||||
|
" def __init__(self, vertexes):\n",
|
||||||
|
" self.vertexes = vertexes \n",
|
||||||
|
" \n",
|
||||||
|
" def __iter__(self):\n",
|
||||||
|
" self.index = -1\n",
|
||||||
|
" return self\n",
|
||||||
|
" \n",
|
||||||
|
" def __next__(self):\n",
|
||||||
|
" self.index += 1\n",
|
||||||
|
" if self.index == len(self.vertexes):\n",
|
||||||
|
" raise StopIteration\n",
|
||||||
|
" return self.vertexes[self.index]\n",
|
||||||
|
" \n",
|
||||||
|
"for v in Figura([Punkt(2,3), Punkt(3,4), Punkt(0, 0)]):\n",
|
||||||
|
" print(v)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Atrybuty i metody statyczne"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 16,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"0\n",
|
||||||
|
"0\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Klasa:\n",
|
||||||
|
" atrybut = 0\n",
|
||||||
|
"\n",
|
||||||
|
"klasa = Klasa()\n",
|
||||||
|
"print(Klasa.atrybut)\n",
|
||||||
|
"print(klasa.atrybut)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Jestem statyczna!\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"class Klasa:\n",
|
||||||
|
" def __init__(self):\n",
|
||||||
|
" self.t = 0\n",
|
||||||
|
" def metoda():\n",
|
||||||
|
" print(\"Jestem statyczna!\")\n",
|
||||||
|
"\n",
|
||||||
|
"Klasa.metoda()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Wyjątki"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "FileNotFoundError",
|
||||||
|
"evalue": "[Errno 2] No such file or directory: 'nieistniejący_plik.txt'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\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;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nieistniejący_plik.txt'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"with open(\"nieistniejący_plik.txt\") as plik:\n",
|
||||||
|
" content = plik.read()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"try:\n",
|
||||||
|
" with open(\"nieistniejący_plik.txt\") as plik:\n",
|
||||||
|
" content = plik.read()\n",
|
||||||
|
"except FileNotFoundError:\n",
|
||||||
|
" contenct = \"\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Warning [Errno 2] No such file or directory: 'nieistniejący_plik.txt'\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"try:\n",
|
||||||
|
" with open(\"nieistniejący_plik.txt\") as plik:\n",
|
||||||
|
" content = plik.read()\n",
|
||||||
|
"except FileNotFoundError as e:\n",
|
||||||
|
" print(\"Warning {}\".format(e))\n",
|
||||||
|
" contenct = \"\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 28,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Warning [Errno 2] No such file or directory: 'nieistniejący_plik.txt'\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"try:\n",
|
||||||
|
" with open(\"nieistniejący_plik.txt\") as plik:\n",
|
||||||
|
" content = plik.read()\n",
|
||||||
|
"except Exception as e:\n",
|
||||||
|
" print(\"Warning {}\".format(e))\n",
|
||||||
|
" contenct = \"\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"try:\n",
|
||||||
|
" with open(\"nieistniejący_plik.txt\") as plik:\n",
|
||||||
|
" content = plik.read()\n",
|
||||||
|
"except:\n",
|
||||||
|
" contenct = \"\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 30,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"class Figura:\n",
|
||||||
|
" def __init__(self, vertexes):\n",
|
||||||
|
" if len(vertexes) == 0:\n",
|
||||||
|
" raise Exception(\"Empty list of vertexes\")\n",
|
||||||
|
" self.vertexes = vertexes"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 35,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true,
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "slide"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"class MyError(Exception):\n",
|
||||||
|
" def __init__(self, text):\n",
|
||||||
|
" self.text = text\n",
|
||||||
|
" def __str__(self):\n",
|
||||||
|
" return self.text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 36,
|
||||||
|
"metadata": {
|
||||||
|
"slideshow": {
|
||||||
|
"slide_type": "fragment"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "MyError",
|
||||||
|
"evalue": "Coś poszło nie tak!",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\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;31mMyError\u001b[0m: Coś poszło nie tak!"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"raise MyError(\"Coś poszło nie tak!\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"celltoolbar": "Slideshow",
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.6.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
18
labs04/README.md
Normal file
18
labs04/README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
**ć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).
|
||||||
|
|
||||||
|
**ć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.
|
||||||
|
|
||||||
|
**ćwiczenie 3 (zadanie domowe) **
|
||||||
|
Stwórz klasę ``Point``, która będzie reprezentować punkt w przestrzeni wielowymiarowej:
|
||||||
|
* Konstruktor ma przyjąc tylko 1 parametr: listę współrzednych. Wykorzystaj funkcję z pierwszego zadania, żeby sprawdzić, czy lista zawiera wyłącznie liczby.
|
||||||
|
* Napisz metodę add, która dida dwa punkty po współrzędnych i zwróci obiekt typu ``Punkt``. Zaimplementuj własny wyjątek ``DimensionError``, który zostaje wyrzucony, jeżeli dodawany punkt ma inny wymiar.
|
||||||
|
* Napisz metodę ``to\_string``, która zwróci łancuch znakowy, który w czytelny sposób przedstawi punkt.
|
||||||
|
* Napisz metodę __len__, która zwróci liczbę współrzędnych punktu. Zobacz, czy możesz teraz wywołać funkcję len na obiekcie typy punkt.
|
||||||
|
* Napisz metodę __str__, która bedzie działać dokładnie tak samo jak metoda ``to_string``. Wyświetl obiekt typy Point korzystając z funkcji print.
|
||||||
|
|
||||||
|
|
3
labs04/task01.py
Normal file
3
labs04/task01.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
3
labs04/task02.py
Normal file
3
labs04/task02.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
3
labs04/task03.py
Normal file
3
labs04/task03.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
297
labs05/Lab05.ipynb
Normal file
297
labs05/Lab05.ipynb
Normal 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
20
labs05/README.md
Normal 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
0
labs05/__init__.py
Normal file
29
labs05/argparse_min.py
Normal file
29
labs05/argparse_min.py
Normal 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
11
labs05/lib.py
Normal 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
18
labs05/main.py
Normal 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()
|
11
labs05/task00.py
Normal file
11
labs05/task00.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
def suma(liczby):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(summa([1, 2, 3, 4]))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
0
labs05/task01.py
Normal file
0
labs05/task01.py
Normal file
0
labs05/task02.py
Normal file
0
labs05/task02.py
Normal file
0
labs05/task03.py
Normal file
0
labs05/task03.py
Normal file
39
labs05/task04.py
Normal file
39
labs05/task04.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Implementacja narzedzia ``wc`` z linuksa (word counter).
|
||||||
|
Zwraca liczbę słów, znaków i linii.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
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 words. """
|
||||||
|
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 """
|
||||||
|
print(wc(sys.stdin.read()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
0
labs05/tools/__init__.py
Normal file
0
labs05/tools/__init__.py
Normal file
38
labs05/tools/fib.py
Normal file
38
labs05/tools/fib.py
Normal 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
874
labs06/Pandas.ipynb
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user