From 7ddeb4d38c5d1a9976a7051a3960fbef0dd8cbbc Mon Sep 17 00:00:00 2001 From: s45156 Date: Sun, 19 Nov 2017 15:44:59 +0100 Subject: [PATCH] changed files --- labs02/task02.py | 7 +++++-- labs02/task03.py | 9 ++++++++- labs02/task04.py | 13 ++++++++++++- labs02/task05.py | 7 +++++-- labs02/task06.py | 4 +++- labs02/task10.py | 2 +- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/labs02/task02.py b/labs02/task02.py index a6d6321..fad7659 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -5,8 +5,11 @@ 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 or year % 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..d24cf2b 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -13,7 +13,14 @@ jak 'set', która przechowuje elementy bez powtórzeń.) def oov(text, vocab): - pass + list_of_words = [] + text_splitted = text.split() + # print(text_splitted) + for word in text_splitted: + if word.lower() not in vocab: + list_of_words.append(word) + return list_of_words + diff --git a/labs02/task04.py b/labs02/task04.py index 37413f1..3b99885 100644 --- a/labs02/task04.py +++ b/labs02/task04.py @@ -7,7 +7,18 @@ 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: + # return sum(range(n + 1)) + ranges = range(n + 1) + if n < 1: + return 0 + else: + return sum(ranges) + + + def tests(f): diff --git a/labs02/task05.py b/labs02/task05.py index f59268a..7067830 100644 --- a/labs02/task05.py +++ b/labs02/task05.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - +import math """ Napisz funkcję euclidean_distance obliczającą odległość między dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako @@ -10,7 +10,10 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): - pass + dist = [(a - b) ** 2 for a, b in zip(x, y)] + dist = math.sqrt(sum(dist)) + 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..53140fb 100644 --- a/labs02/task06.py +++ b/labs02/task06.py @@ -10,7 +10,9 @@ 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!" + new = n.split('N') def tests(f): inputs = [[5], [6], [2]] diff --git a/labs02/task10.py b/labs02/task10.py index f380f0a..58d40d2 100644 --- a/labs02/task10.py +++ b/labs02/task10.py @@ -13,7 +13,7 @@ def pokemon_speak(text): 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):