From c4cf32a7f825dbf51dda524271392ba67a08ea60 Mon Sep 17 00:00:00 2001 From: Magda Zganiacz Date: Sat, 2 Jun 2018 19:40:33 +0200 Subject: [PATCH] Zadanie domowe --- labs02/task07.py | 5 ++++- labs02/task08.py | 6 +++++- labs02/task09.py | 9 +++++++-- labs02/task10.py | 10 +++++++++- labs02/task11.py | 12 ++++++++++-- labs04/05.py | 16 ++++++++++++++++ 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 labs04/05.py diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..efc9ac3 100644 --- a/labs02/task07.py +++ b/labs02/task07.py @@ -6,7 +6,10 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca sumę kodów ASCII znaków. """ def char_sum(text): - pass + sum = 0 + for x in text: + sum += ord(x) + return sum def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..5c0cd35 100644 --- a/labs02/task08.py +++ b/labs02/task08.py @@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n. """ def sum_div35(n): - pass + sum = 0 + for i in range(n): + if i%3 == 0 or i%5 == 0: + sum += i + return sum def tests(f): inputs = [[10], [100], [3845]] diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..eff813d 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,8 +9,13 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass - + slownik = {'e':'3', 'l':'1', 'o':'0', 't':'7'} + napis = '' + for i in text: + if i in slownik: + napis += slownik[i] + else: napis += i + return napis def tests(f): inputs = [['leet'], ['do not want']] diff --git a/labs02/task10.py b/labs02/task10.py index 58d40d2..36907fd 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,7 +9,15 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + a = 0 + napis = '' + for i in text: + a += 1 + if a%2 == 1: + i = i.upper() + else: i + napis += i + return napis def tests(f): diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..8f10e7b 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,7 +9,15 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass + lista = [] + str1 = set(string1) + str2 = set(string2) + for i in str1: + for j in str2: + if i == j and i != ' ': + lista += i + lista.sort() + return lista def tests(f): @@ -23,4 +31,4 @@ def tests(f): return "TESTS PASSED" if __name__ == "__main__": - print(tests(common_chars)) + print(tests(common_chars)) \ No newline at end of file diff --git a/labs04/05.py b/labs04/05.py new file mode 100644 index 0000000..7735745 --- /dev/null +++ b/labs04/05.py @@ -0,0 +1,16 @@ +import glob +import os + +max_wartosc_bleu = 0 +max_nazwa_pliku ='' +for nazwa_pliku in glob.glob('scores/*'): + with open(nazwa_pliku, 'r') as plik: + for linia in plik.readlines(): + wartosc_bleu = linia.split(' ')[2] + wartosc_bleu = float(wartosc_bleu.strip(',')) + if wartosc_bleu > max_wartosc_bleu: + max_wartosc_bleu = wartosc_bleu + max_nazwa_pliku = nazwa_pliku + +print(max_nazwa_pliku) +