1
0
forked from tdwojak/Python2018

labs02 ready

This commit is contained in:
Kuba 2018-05-14 23:01:58 +02:00
parent a5f73d423a
commit d0595e3128
7 changed files with 15 additions and 19 deletions

View File

@ -17,13 +17,6 @@ def days_in_year(days):
else:
return 365
# To determine whether a year is a leap year, follow these steps:
# If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
# If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
# If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
# The year is a leap year (it has 366 days).
# The year is not a leap year (it has 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]
outputs = [365, 366, 365, 366, 365]

View File

@ -13,8 +13,7 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
words = text.lower().split()
return (set(words) - set(vocab))
return (set(text.lower().split()) - set(vocab))
def tests(f):
inputs = [("this is a string , which i will use for string testing",

View File

@ -10,10 +10,7 @@ np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
def euclidean_distance(x, y):
dist = 0
for i, j in zip(x, y):
dist += (i-j) ** 2
return m.sqrt(dist)
return m.sqrt(sum((i-j)**2 for i, j in zip(x, y)))
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -9,8 +9,11 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
pass
words_dict = { 'e': '3', 'l': '1', 'o': '0', 't': '7' }
for letter in text:
if letter in words_dict:
text = text.replace(letter, words_dict[letter])
return text
def tests(f):
inputs = [['leet'], ['do not want']]

View File

@ -9,8 +9,13 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
result = []
for i in range(len(text)):
if i % 2 == 0:
result.append(text[i].upper())
else:
result.append(text[i])
return ''.join(result)
def tests(f):
inputs = [['pokemon'], ['do not want'], ['POKEMON']]

View File

@ -11,7 +11,6 @@ Oba napisy będą składać się wyłacznie z małych liter.
def common_chars(string1, string2):
return sorted(set(string1.replace(' ', '')) & set(string2.replace(' ', '')))
def tests(f):
inputs = [["this is a string", "ala ma kota"]]
outputs = [['a', 't']]

View File

@ -6,7 +6,7 @@ def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
return 0
return a + b
def tests(f):
inputs = [(2, 3), (0, 0), (1, 1)]