From d6f4abe5622a975fcf6a8eee7774ded9eb764bf8 Mon Sep 17 00:00:00 2001 From: s441403 Date: Sun, 13 May 2018 12:54:21 +0200 Subject: [PATCH] task 05-10 --- labs02/task05.py | 8 ++++++-- labs02/task06.py | 6 +++++- labs02/task07.py | 4 +++- labs02/task08.py | 9 ++++++++- labs02/task09.py | 12 +++++++++++- labs02/task10.py | 5 ++++- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/labs02/task05.py b/labs02/task05.py index 24ae650..0d66f58 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -10,8 +10,12 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - d= math.pow(x) + math.pow(y) - distance = math.sqrt(d) + counter = 0 + for i in range(len(x)): + d= math.pow(x[i] - y[i],2) + counter += d + distance = math.sqrt(counter) + return distance 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..3dd6672 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,11 @@ 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: + big_no = "N" + "O" * n + "!" + return big_no def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task07.py b/labs02/task07.py index 80cbd37..9968be4 100644 --- a/labs02/task07.py +++ b/labs02/task07.py @@ -6,7 +6,9 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca sumę kodów ASCII znaków. """ def char_sum(text): - pass + a = list(text) + lista = [ord(x) for x in a] + return sum(lista) def tests(f): inputs = [["this is a string"], ["this is another string"]] diff --git a/labs02/task08.py b/labs02/task08.py index 252b10d..3410985 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 + 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..aacf969 100644 --- a/labs02/task09.py +++ b/labs02/task09.py @@ -9,7 +9,17 @@ Np. leet('leet') powinno zwrócić '1337'. def leet_speak(text): - pass + lista = list(text) + słownik = {'1':'l', '3':'e', '0':'o', '7':'t'} + lista_wartosci = słownik.values() + lista_mod = [] + + for i in range(len(lista)): + for key, value in słownik.items(): + if lista[i] in value: + lista[i]=key + wynik = "".join(lista) + return wynik def tests(f): diff --git a/labs02/task10.py b/labs02/task10.py index 58d40d2..978be40 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -9,7 +9,10 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. def pokemon_speak(text): - pass + lista = list(text) + lista[::2].capitalize() + wynik = "".join(lista) + return wynik def tests(f):