1
0
forked from tdwojak/Python2018

'zadaniedomowe1'

This commit is contained in:
dkuam 2018-06-03 07:24:24 +02:00
parent 577882804b
commit 56c557a319
81 changed files with 624 additions and 2 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.6.2 (C:\ProgramData\Anaconda3\python.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="TestRunnerService"> <component name="TestRunnerService">

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.2 (C:\ProgramData\Anaconda3\python.exe)" project-jdk-type="Python SDK" />
</project> </project>

183
.idea/workspace.xml Normal file
View File

@ -0,0 +1,183 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="5b2363b3-657e-422b-96b9-b9c3a7d73e5f" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs02/task07.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs02/task08.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs02/task09.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs02/task10.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs02/task11.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/README.md" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/examples/06_execution_time.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/examples/25_ip2geolocation.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/examples/fib.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/examples/myip.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/examples/wc.py" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/haslo.txt" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/haslo2.txt" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter10000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter100000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter110000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter120000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter130000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter140000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter150000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter160000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter170000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter180000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter190000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter20000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter200000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter210000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter220000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter230000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter240000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter250000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter260000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter270000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter280000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter290000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter30000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter300000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter310000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter320000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter330000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter340000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter350000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter360000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter370000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter380000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter390000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter40000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter400000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter410000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter420000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter430000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter440000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter450000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter460000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter470000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter480000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter490000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter50000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter500000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter510000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter520000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter530000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter540000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter550000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter560000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter570000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter580000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter590000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter60000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter600000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter610000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter620000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter630000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter640000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter70000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter80000.npz.bleu" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/ZadanieDomowe1/labs04/scores/model.iter90000.npz.bleu" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/Python2018.iml" afterPath="$PROJECT_DIR$/.idea/Python2018.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="task07.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ZadanieDomowe1/labs02/task07.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="22" column="0" lean-forward="true" selection-start-line="22" selection-start-column="0" selection-end-line="22" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="20" />
<option name="y" value="20" />
<option name="width" value="1400" />
<option name="height" value="820" />
</component>
<component name="PropertiesComponent">
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="5b2363b3-657e-422b-96b9-b9c3a7d73e5f" name="Default" comment="" />
<created>1528000731222</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1528000731222</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1456" height="876" extended-state="6" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Data View" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/ZadanieDomowe1/labs02/task07.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="22" column="0" lean-forward="true" selection-start-line="22" selection-start-column="0" selection-end-line="22" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
"""
ord() - kod ASCII dla jednego znaku
print(ord('a'))
"""
def char_sum(text):
suma_ascii = 0 # zerujemy (needto?)
for znak in text:
suma_ascii += ord(znak) # suma_ascii = ord(x) + suma_ascii
return 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))

View File

@ -0,0 +1,31 @@
#!/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):
suma = 0
for liczba in range(1,n): # range(1,n) przedzial liczb mniejszych niz n
if liczba % 3 == 0:
suma += liczba
elif liczba % 5 == 0:
suma += liczba
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))

View File

@ -0,0 +1,26 @@
#!/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):
return text.replace('e', '3').replace('l', '1').replace('o', '0').replace('t', '7')
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))

View File

@ -0,0 +1,40 @@
#!/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):
pokemon = ''
capitalize = True
for litera in text:
if capitalize is True:
pokemon += litera.upper()
else:
pokemon += litera
capitalize = not capitalize
return pokemon
"""
test
print(pokemon_speak('tekst pisany malymi literami'))
"""
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))

View File

@ -0,0 +1,32 @@
#!/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):
string1bezspacji = string1.replace(' ','') # trzeba spacje usunac
string2bezspacji = string2.replace(' ','')
return list(''.join(sorted(set(string1bezspacji) & set(string2bezspacji))))
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))

View File

@ -0,0 +1,34 @@
# Laboratoria 4
## Zadania
**ćwiczenie 0** NIE TRZEBA ROBIC!!!!
Uruchom programy z katalogu `examples` i zobacz ich kod. Spróbuj odgadnąć, co robią konkretne linie w kodzie.
**ćwiczenie 1** NIE TRZEBA ROBIC!!!!
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** NIE TRZEBA ROBIC!!!!
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** NIE TRZEBA ROBIC!!!!
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 obiektu typu JSON.
* Wyświetl wartość kursu EUR do PLN.
**ćwiczenie 4** NIE TRZEBA ROBIC!!!!
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** TRZEBA ZROBIĆ JAKO ZADANIE DOMOWE!!!
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ą).
Cwiczenie 5 zrobić do 2.06.2018 nawet do 5 w nocy.

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
ExecutionTime
This class is used for timing execution of code.
For example:
timer = ExecutionTime()
print 'Hello world!'
print 'Finished in {} seconds.'.format(timer.duration())
"""
import time
import random
class ExecutionTime:
def __init__(self):
self.start_time = time.time()
def duration(self):
return time.time() - self.start_time
# ---- run code ---- #
timer = ExecutionTime()
sample_list = list()
my_list = [random.randint(1, 888898) for num in
range(1, 1000000) if num % 2 == 0]
print('Finished in {} seconds.'.format(timer.duration()))

View File

@ -0,0 +1,31 @@
import csv
import requests
def get_address():
"""
Given a CSV file, this function returns a list of lists
where each element (list) in the outer list contains the
row info from the csv file.
"""
all_addresses = [requests.get('http://ip.42.pl/raw').text.strip()]
return all_addresses
def get_geolocation(ip_address):
"""
Given a list of lists from `get_addresses()`, this function
returns an updated lists of lists containing the geolocation.
"""
print("Getting geo information...")
# update header
# get geolocation
for line in all_the_ip_address:
print("Grabbing geo info")
r = requests.get('https://freegeoip.net/json/{0}'.format(line))
print([str(r.json()['country_name']), str(r.json()['city'])])
if __name__ == '__main__':
all_the_ip_address = get_address()
get_geolocation(all_the_ip_address)

View File

@ -0,0 +1,47 @@
#!/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]
for i in [5, 10, 15, 20, 30, 40]:
print("Naive fibonacci for ", i, ":", naive_fibonacci(i))
for i in [5, 10, 15, 20, 30, 40, 100]:
print("cache fibonacci for ", i, ":", cache_fibonacci(i))
for i in [5, 10, 15, 20, 30, 40, 100]:
print("no-recurrent fibonacci for ", i, ":", non_reccurent_fibonacci(i))

View File

@ -0,0 +1,11 @@
#!/usr/bin/env python
"""
This simple script fetches your IP as seen by web pages, and displays it.
Execute this script locally like that:
$ curl -s https://raw.github.com/gist/3389407/myip.py | python
"""
import requests
print(requests.get('http://ip.42.pl/raw').text)

View 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()

View File

@ -0,0 +1,2 @@
W Paryżu najlepsze kasztany są na placu Pigalle
Zuzanna lubi je tylko jesienią.

View File

@ -0,0 +1 @@
corect horse battery staple

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View File

@ -0,0 +1 @@
BLEU = 0, 0/0/0/0 (BP=0, ratio=0, hyp_len=0, ref_len=0)

View 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)

View 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)

View 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)

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
**ć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ą).
"""
import glob as gl
import pandas as pd