diff --git a/labs02/task02.py b/labs02/task02.py index a6d6321..280246a 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -6,7 +6,11 @@ """ 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..50567e6 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,7 +13,11 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): - pass + rett = list() + for s in text.lower().split(): + if not s in vocab: + rett.append(s) + return set(rett) diff --git a/labs02/task04.py b/labs02/task04.py index 37413f1..4c73a83 100644 --- a/labs02/task04.py +++ b/labs02/task04.py @@ -7,7 +7,12 @@ 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 + sum = 0 + 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..8dda0e1 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import math as mt """ Napisz funkcję euclidean_distance obliczającą odległość między @@ -10,7 +11,15 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - pass + x1 = x[0] + y1 = x[1] + z1 = x[2] + + x2 = y[0] + y2 = y[1] + z2 = y[2] + + return mt.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2) 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..0e8c103 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,13 @@ 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!'" + t = list('N') + for i in range(n): + t.append('O') + return ''.join(t) + '!' + def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..557c0e9 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 + s = 0 + for z in text: + s +=ord(z) + return s def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..30b6758 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 + s = 0 + for i in range(n): + if (i % 3 == 0) or (i % 5 == 0): + s+=i + return s def tests(f): inputs = [[10], [100], [3845]] diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..95116a4 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -7,9 +7,17 @@ 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'. """ +import string def leet_speak(text): - pass + dt = {"e":"3", "l":"1", "o":"0", "t":"7"} + ltx = text.lower() + ret = text + "" + for k in list(ltx): + v = dt.get(k) + if v is not None: + ret = ret.replace(k, v) + return ret def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index f380f0a..224f3f5 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -7,13 +7,19 @@ Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą liter na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. """ +import string as str def pokemon_speak(text): - pass + lt = list(text) + for i in range(len(lt)): + if i%2 == 0: + lt[i] = lt[i].upper() + return ''.join(lt) + 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..d3024d3 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,8 +9,13 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass - + t1 = list(''.join(string1.split(' '))) + t2 = list(''.join(string2.split(' '))) + rett = list() + for lit in t1: + if lit in t2: + rett.append(lit) + return sorted(set(rett)) def tests(f): inputs = [["this is a string", "ala ma kota"]] diff --git a/labs02/test_task.py b/labs02/test_task.py index 5879768..d8fb9a6 100755 --- a/labs02/test_task.py +++ b/labs02/test_task.py @@ -6,7 +6,7 @@ def suma(a, b): """ Napisz funkcję, która zwraca sumę elementów. """ - pass + return a+b def tests(f): inputs = [(2, 3), (0, 0), (1, 1)]