From fc40cd3b0211b058a55b27fabe367851c1ee8634 Mon Sep 17 00:00:00 2001 From: s45160 Date: Sun, 19 Nov 2017 15:44:36 +0100 Subject: [PATCH] update all tasks --- labs02/task01.py | 2 +- labs02/task02.py | 5 ++++- labs02/task03.py | 7 ++++++- labs02/task04.py | 8 +++++++- labs02/task05.py | 2 +- labs02/task06.py | 5 ++++- labs02/task07.py | 5 ++++- labs02/task08.py | 9 ++++++++- labs02/task09.py | 13 ++++++++++++- labs02/task10.py | 13 +++++++++++-- labs02/task11.py | 8 +++++++- 11 files changed, 65 insertions(+), 12 deletions(-) diff --git a/labs02/task01.py b/labs02/task01.py index 7c08c56..ee754f9 100644 --- a/labs02/task01.py +++ b/labs02/task01.py @@ -7,7 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach. """ def even_elements(lista): - pass + return lista[::2] def tests(f): diff --git a/labs02/task02.py b/labs02/task02.py index a6d6321..f048fb8 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..b392d02 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,7 +13,12 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): - pass + wynik = set() + for wyraz in text.split(' '): + if wyraz.lower() not in vocab: + wynik.add(wyraz.lower()) + return wynik + diff --git a/labs02/task04.py b/labs02/task04.py index 37413f1..6a1a8bd 100644 --- a/labs02/task04.py +++ b/labs02/task04.py @@ -7,7 +7,13 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0. """ def sum_from_one_to_n(n): - pass + wynik = 0 + if n < 1: + return 0 + else: + for i in range(n): + wynik += (i+1) + return wynik def tests(f): diff --git a/labs02/task05.py b/labs02/task05.py index f59268a..cc16ae4 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -10,7 +10,7 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - pass + return ((x[0]-y[0])**2 + (x[1]-y[1])**2 + (x[2]-y[2])**2)**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..19bc54f 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): - pass + if n < 5: + return "It's not a Big 'No!'" + else: + return "N" + n*"O" + "!" def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..d6618d7 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 + wynik = 0 + for litera in text: + wynik += ord(litera) + return wynik def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..a55bae7 100644 --- a/labs02/task08.py +++ b/labs02/task08.py @@ -7,7 +7,14 @@ przez 3 lub 5 mniejszych niż n. """ def sum_div35(n): - pass + wynik = 0 + if n<0: + return 0 + else: + for i in range(n): + if i % 3 == 0 or i % 5 == 0: + wynik += i + return wynik def tests(f): inputs = [[10], [100], [3845]] diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..27a399c 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,7 +9,18 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass + text = text.lower() + text = text.replace('o', '0') + text = text.replace('l', '1') + text = text.replace('z', '2') + text = text.replace('e', '3') + text = text.replace('h', '4') + text = text.replace('s', '5') + text = text.replace('g', '6') + text = text.replace('t', '7') + text = text.replace('b', '8') + + return text def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index f380f0a..605c452 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,11 +9,20 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + wynik = [] + indeks = 0 + for litera in text: + if indeks % 2 == 0: + wynik.append(litera.upper()) + else: + wynik.append(litera) + indeks += 1 + + return ''.join(wynik) def tests(f): - inputs = [['pokemon'], ['do not want'], 'POKEMON'] + inputs = [['pokemon'], ['do not want'], ['POKEMON']] outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON'] for input, output in zip(inputs, outputs): diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..7ecd406 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,7 +9,13 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass + common = [] + for lit in string1: + if lit in string2 and lit != ' ': + common.append(lit) + common = list(set(common)) + common.sort() + return common def tests(f):