From 7714575879affceb323c6a76ad2eb5e419ecc31b Mon Sep 17 00:00:00 2001 From: s327689 Date: Sun, 13 May 2018 12:54:51 +0200 Subject: [PATCH 1/8] my results --- labs02/intro_task.py | 29 ++++++++++++++++++----------- labs02/task01.py | 4 +++- labs02/task02.py | 5 ++++- labs02/task03.py | 14 +++++++++++++- labs02/task04.py | 9 ++++++++- labs02/task05.py | 8 +++++++- labs02/task06.py | 2 +- 7 files changed, 54 insertions(+), 17 deletions(-) diff --git a/labs02/intro_task.py b/labs02/intro_task.py index 92164f5..a98f4c4 100644 --- a/labs02/intro_task.py +++ b/labs02/intro_task.py @@ -9,48 +9,55 @@ Zadania wprowadzające do pierwszych ćwiczeń. """ Wypisz na ekran swoje imię i nazwisko. """ - +print("Agnieszka Wagner") """ Oblicz i wypisz na ekran pole koła o promienie 10. Jako PI przyjmij 3.14. """ - +pole = 3.14 * (10.0 ** 2) +print(pole) """ Stwórz zmienną pole_kwadratu i przypisz do liczbę: pole kwadratu o boku 3. """ - +pole_kwadratu = 3 ** 2 """ Stwórz 3 elementową listę, która zawiera nazwy 3 Twoich ulubionych owoców. Wynik przypisz do zmiennej `owoce`. """ - +owoce = ['jabłko', 'gruszka', 'malina'] """ Dodaj do powyższej listy jako nowy element "pomidor". """ - +owoce.append("pomidor") +print(owoce) """ Usuń z powyższej listy drugi element. """ - - +owoce.pop(1) +print(owoce) """ Rozszerz listę o tablice ['Jabłko', "Gruszka"]. """ - +owoce.append(['Jabłko', "Gruszka"]) +print(owoce) """ Wyświetl listę owoce, ale bez pierwszego i ostatniego elementu. """ - +print(owoce[1:-1]) """ Wyświetl co trzeci element z listy owoce. """ - +print(owoce[::3]) """ Stwórz pusty słownik i przypisz go do zmiennej magazyn. """ - +magazyn = {} """ Dodaj do słownika magazyn owoce z listy owoce, tak, aby owoce były kluczami, zaś wartościami były równe 5. """ +for i in owoce: + magazyn[i] = 5 + +print(magazyn) \ No newline at end of file diff --git a/labs02/task01.py b/labs02/task01.py index 7c08c56..81223be 100644 --- a/labs02/task01.py +++ b/labs02/task01.py @@ -7,7 +7,8 @@ która zawiera tylko elementy z list o parzystych indeksach. """ def even_elements(lista): - pass + return(lista[::2]) + def tests(f): @@ -23,3 +24,4 @@ def tests(f): if __name__ == "__main__": print(tests(even_elements)) + diff --git a/labs02/task02.py b/labs02/task02.py index a6d6321..e48e43a 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -6,7 +6,10 @@ """ def days_in_year(days): - pass + if (days % 4 == 0 and ((days % 100 != 0) or (days % 400 == 0))): + return 366 + else: + return 365 def tests(f): inputs = [[2015], [2012], [1900], [2400], [1977]] diff --git a/labs02/task03.py b/labs02/task03.py index a1c3a85..5445f39 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,7 +13,13 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): - pass + flag = [] + textSegm = set(text.split(' ')) + for word in textSegm: + if word not in vocab: + flag.append(word) + return flag + @@ -30,3 +36,9 @@ def tests(f): if __name__ == "__main__": print(tests(oov)) + + +text = "this is a string , which i will use for string testing" +textSegm = set(text.split(' ')) +print(textSegm) +len(textSegm) \ No newline at end of file diff --git a/labs02/task04.py b/labs02/task04.py index 37413f1..44fb996 100644 --- a/labs02/task04.py +++ b/labs02/task04.py @@ -7,7 +7,14 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0. """ def sum_from_one_to_n(n): - pass + sum = 0 + if n < 1: + return 0 + else: + for i in range(n+1): + sum += i + return sum + def tests(f): diff --git a/labs02/task05.py b/labs02/task05.py index f59268a..0e02994 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -10,7 +10,13 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - pass + + sum = 0 + for i in range(len(x)): + result = (x[i] - y[i])**2 + sum += result + return(sum**0.5) + def tests(f): inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]] diff --git a/labs02/task06.py b/labs02/task06.py index ff4a9d3..7c3ef0e 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,7 @@ ma być zwracany napis "It's not a Big 'No!'". """ def big_no(n): - pass + def tests(f): inputs = [[5], [6], [2]] From 84ac4edce92f077458b80e6672b3697a15afb1d4 Mon Sep 17 00:00:00 2001 From: s327689 Date: Fri, 1 Jun 2018 17:09:47 +0200 Subject: [PATCH 2/8] passed --- labs02/task06.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/labs02/task06.py b/labs02/task06.py index 7c3ef0e..9253c84 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,10 @@ ma być zwracany napis "It's not a Big 'No!'". """ def big_no(n): - + if n >= 5 : + return("N"+("O"*n)+"!") + else : + return("It's not a Big 'No!'") def tests(f): inputs = [[5], [6], [2]] From 8e45dba2e5744276986e3fb8a3d2de36c167d880 Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Fri, 1 Jun 2018 17:32:25 +0200 Subject: [PATCH 3/8] passed --- labs02/task07.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..5cf4520 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 + x = 0 + for c in text: + x += ord(c) + return (x) def tests(f): inputs = [["this is a string"], ["this is another string"]] From fd1d22ef4df2657508e3927e5fa3bd91d339a66b Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Fri, 1 Jun 2018 17:55:41 +0200 Subject: [PATCH 4/8] passed --- labs02/task08.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..5eefb77 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 + x = 0 + for i in range(n): + if ( i % 3 == 0 or i % 5 == 0 ) : + x += i + return(x) def tests(f): inputs = [[10], [100], [3845]] From 6d503b377cabc9585e946010a6d6f670c03a9230 Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Fri, 1 Jun 2018 18:38:11 +0200 Subject: [PATCH 5/8] passed --- labs02/task09.py | 4 +++- labs02/task10.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..2f429b2 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,7 +9,9 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass + for i in text : + if i == "e" : + def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index 58d40d2..d2bbb70 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,7 +9,13 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + if text[:].isupper() == True : + return(text) + else : + R = [''] * len(text) + R[::2], R[1::2] = text[::2].upper(), text[1::2].lower() + R = ''.join(R) + return(R) def tests(f): From 96214d2d3f47d0abf622ba60ea6661e4cccefe8a Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Fri, 1 Jun 2018 19:04:52 +0200 Subject: [PATCH 6/8] passed --- labs02/task11.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..befe374 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,8 +9,12 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass - + string1 = "this is a string" + string2 = "ala ma kota" + s = set(string1.replace(" ", "")) + t = set(string2.replace(" ", "")) + intersect = s & t + return(sorted(list(intersect))) def tests(f): inputs = [["this is a string", "ala ma kota"]] From bac748992fb54cd8066f0b1c011cbd69de909a32 Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Fri, 1 Jun 2018 19:28:21 +0200 Subject: [PATCH 7/8] passed --- labs02/task09.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/labs02/task09.py b/labs02/task09.py index 2f429b2..82ab67f 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,10 +9,15 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - for i in text : - if i == "e" : - - + if 'e' in text : + text = text.replace("e", "3") + if "l" in text : + text = text.replace("l", "1") + if "o" in text : + text = text.replace("o", "0") + if "t" in text : + text = text.replace("t", "7") + return(text) def tests(f): inputs = [['leet'], ['do not want']] From f4e009d148214adaad9e2e5c0cf7432dee8f4030 Mon Sep 17 00:00:00 2001 From: "wagner.agnieszka" Date: Sun, 3 Jun 2018 00:23:55 +0200 Subject: [PATCH 8/8] passed --- labs04/labs04Task5.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 labs04/labs04Task5.py diff --git a/labs04/labs04Task5.py b/labs04/labs04Task5.py new file mode 100644 index 0000000..d77ed4a --- /dev/null +++ b/labs04/labs04Task5.py @@ -0,0 +1,21 @@ +import glob + +filelist = glob.glob('scores\\*.bleu') +bleu_filename = '' +max_bleu = 0 + + +def find_bleu(bleu_list, max_bleu): + for bleufile in bleu_list: + content = open(bleufile, 'r').read() + bleu = content.split(r',') + bleu_datum = bleu[0].split() + if max_bleu <= float(bleu_datum[2]): + max_bleu = float(bleu_datum[2]) + bleu_filename = bleufile + return bleu_filename, max_bleu + + +# filename, max_bleu = find_bleu([filelist[0]], max_bleu) +filename, max_bleu = find_bleu(filelist, max_bleu) +print(filename) \ No newline at end of file