From 2386b38ffeb899c76b8b683e35a179be240c6ecd Mon Sep 17 00:00:00 2001 From: s45155 Date: Sat, 25 Nov 2017 18:06:51 +0100 Subject: [PATCH] ready for review --- labs02/task01.py | 2 +- labs02/task02.py | 11 +++++++++-- labs02/task03.py | 10 +++++----- labs02/task04.py | 9 ++++++++- labs02/task05.py | 5 ++++- labs02/task06.py | 9 ++++++++- labs02/task07.py | 5 ++++- labs02/task08.py | 7 ++++++- labs02/task09.py | 2 +- labs02/task10.py | 13 ++++++++++--- labs02/task11.py | 9 ++++++++- 11 files changed, 64 insertions(+), 18 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..52fb1e8 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -5,8 +5,15 @@ Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366). """ -def days_in_year(days): - pass +def days_in_year(year): + if year % 4 == 0 and year % 100 == 0 and year % 400 == 0: + return 366 + elif year % 4 == 0 and year % 100 != 0: + return 366 + elif year % 4 == 0 and year % 100 == 0 and year % 400 != 0: + return 365 + else: + return 365 def tests(f): inputs = [[2015], [2012], [1900], [2400], [1977]] diff --git a/labs02/task03.py b/labs02/task03.py index 0487014..e489cea 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,11 +13,11 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): -s=set() -for i in text.split(): - if i not in vocab: - text.lower() -return s + s=set() + for i in text.split(): + if i not in vocab: + s.add(i) + return s diff --git a/labs02/task04.py b/labs02/task04.py index 37413f1..18004eb 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 + if n<1: + return 0 + else: + x=0 + for i in range (n+1): + x=x+i + return x + def tests(f): diff --git a/labs02/task05.py b/labs02/task05.py index f59268a..46dc6d2 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -9,8 +9,11 @@ trzyelementowe listy liczb zmiennoprzecinkowych. np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ + + def euclidean_distance(x, y): - pass + dist=((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/2) + return dist 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..b8e257a 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,14 @@ 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: + tekst="N" + for i in range (n): + tekst += "O" + tekst += "!" + return(tekst) def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..838dd31 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 + suma=0 + for i in range (len(text)): + suma+=ord(text[i]) + return(suma) def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..73cca5e 100644 --- a/labs02/task08.py +++ b/labs02/task08.py @@ -7,7 +7,12 @@ przez 3 lub 5 mniejszych niż n. """ def sum_div35(n): - pass + suma=0 + for i in range(n): + if i%3==0 or i%5==0: + suma+=i + return(suma) + def tests(f): inputs = [[10], [100], [3845]] diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..270957e 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,7 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass + return(text.replace("e","3").replace("l", "1").replace("o", "0").replace("t", "7")) def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index f380f0a..1a39929 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,11 +9,18 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + for i in range(len(text)): + if i == 0: + mytext=''.join(['', text[i].upper()]) + elif i % 2 == 0: + mytext = ''.join([mytext[:i], text[i].upper()]) + else: + mytext = ''.join([mytext[:i], text[i]]) + return (mytext) 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): @@ -23,4 +30,4 @@ def tests(f): return "TESTS PASSED" if __name__ == "__main__": - print(tests(pokemon_speak)) + print(tests(pokemon_speak)) \ No newline at end of file diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..5a34e72 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass + s=[] + s1 = list(set(string1.replace(' ',''))) + s2 = list(set(string2.replace(' ',''))) + for i in s1: + if i in s2: + s.append(i) + s.sort() + return s def tests(f):