diff --git a/labs02/task02.py b/labs02/task02.py index 98a38eb..fab948c 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -6,10 +6,7 @@ """ def days_in_year(days): - if ((days % 4 == 0) and (days % 100 != 0)) or (days % 400 == 0): - return 366 - else: - return 365 + return 366 if ((days % 4 == 0) and (days % 100 != 0)) or (days % 400 == 0) else 365 def tests(f): inputs = [[2015], [2012], [1900], [2400], [1977]] diff --git a/labs02/task03.py b/labs02/task03.py index 8e63b76..e6a2a01 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,9 +13,7 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): - return set( text.split(' ')).difference(vocab) - - + return set(text.split(' ')).difference(vocab) def tests(f): @@ -29,5 +27,6 @@ def tests(f): break return "TESTS PASSED" + if __name__ == "__main__": print(tests(oov)) diff --git a/labs02/task04.py b/labs02/task04.py index 5001cea..69dcf87 100644 --- a/labs02/task04.py +++ b/labs02/task04.py @@ -7,11 +7,7 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0. """ def sum_from_one_to_n(n): - if n < 1 : - return 0 - else: - return reduce(lambda x, y: (x+y), range(1,n+1)) - + return 0 if n < 1 else reduce(lambda x, y: (x+y), range(1,n+1)) def tests(f): inputs = [[999], [-100]] diff --git a/labs02/task05.py b/labs02/task05.py index abfc03f..c1c8c51 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -12,10 +12,7 @@ import math def euclidean_distance(x, y): - a = y[0]-x[0] - b = y[1]-x[1] - c = y[2]-x[2] - return math.sqrt( math.sqrt(a**2+b**2)**2 + c**2) + return math.sqrt(math.sqrt((y[0] - x[0]) ** 2 + (y[1] - x[1]) ** 2) ** 2 + (y[2] - x[2]) ** 2) diff --git a/labs02/task06.py b/labs02/task06.py index b9de6a2..27bedcb 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -9,11 +9,9 @@ równa podanemu argumentem, przy czym jeśli argument jest mniejszy niż 5, ma być zwracany napis "It's not a Big 'No!'". """ + def big_no(n): - if n < 5: - return "It's not a Big 'No!'" - else: - return "N" + n*"O" + "!" + return "It's not a Big 'No!'" if n < 5 else "N" + n * "O" + "!" def tests(f): @@ -26,5 +24,6 @@ def tests(f): break return "TESTS PASSED" + if __name__ == "__main__": print(tests(big_no)) diff --git a/labs02/task10.py b/labs02/task10.py index 2247fb4..84ebc90 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,7 +9,7 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - return ''.join( map( lambda t: t[0]+t[1], zip( text[::2].upper(), text[1::2] ) ) ) + return ''.join([a if idx%2==1 else a.upper() for idx, a in enumerate(text)]) def tests(f): diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..5d2e51e 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,7 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass + return sorted( set(filter(lambda ch: ch.islower(), string1)).intersection(filter(lambda ch: ch.islower(), string2)) ) def tests(f):