From c6a24f1f8e8215f58134ee03348c4507f1874a7d Mon Sep 17 00:00:00 2001 From: s45162 Date: Thu, 30 Nov 2017 21:11:34 +0100 Subject: [PATCH] =?UTF-8?q?=C4=87wiczenia=201.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- labs02/task05.py | 6 +++++- labs02/task06.py | 8 +++++++- labs02/task07.py | 2 +- labs02/task08.py | 7 ++++++- labs02/task09.py | 10 +++++++++- labs02/task10.py | 9 ++++++++- labs02/task11.py | 7 +++++-- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/labs02/task05.py b/labs02/task05.py index f59268a..fd12604 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -10,7 +10,11 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - pass + if len(x)!=len(y): + return 'Error' + else: + return ((x[0]-y[0])**2+(x[1]-y[1])**2+(x[2]-y[2])**2)**(1/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..a0ea9d3 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!'" + else: + S="N" + for i in range(n): + S+="O" + return S+"!" def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..fe9405b 100644 --- a/labs02/task07.py +++ b/labs02/task07.py @@ -6,7 +6,7 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca sumę kodów ASCII znaków. """ def char_sum(text): - pass + return sum(ord(i) for i in text) def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..1bc146f 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 + sum=0 + for i in range(n): + if (i%5==0) or (i%3==0): + sum+=i + return sum + def tests(f): inputs = [[10], [100], [3845]] diff --git a/labs02/task09.py b/labs02/task09.py index 9045054..34ac5d7 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,7 +9,15 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass + tekst="" + slownik = {"e": "3", "l": "1", "o": "0", "t":"7"} + for i in text: + if i in slownik: + tekst+=slownik[i] + else: + tekst+=i + return tekst + def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index 58d40d2..d5a74e9 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,7 +9,14 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + s="" + for i in range(len(text)): + if (i%2==0): + s+=text[i].upper() + else: + s+=text[i] + return s + def tests(f): diff --git a/labs02/task11.py b/labs02/task11.py index 7d36767..5031a88 100644 --- a/labs02/task11.py +++ b/labs02/task11.py @@ -9,8 +9,11 @@ Oba napisy będą składać się wyłacznie z małych liter. """ def common_chars(string1, string2): - pass - + b =[] + for i in sorted(string1): + if (i in sorted(string2)) and i!=" " and i not in b: + b.append(i) + return b def tests(f): inputs = [["this is a string", "ala ma kota"]]