1
0
Fork 0

Zadania domowe labs02

This commit is contained in:
szwedek 2017-11-29 14:43:45 +01:00
parent b62e43effe
commit fa0165c8f4
12 changed files with 56 additions and 17 deletions

View File

@ -7,7 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
pass
return lista[::2]
def tests(f):

View File

@ -5,8 +5,12 @@
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
"""
def days_in_year(days):
pass
def days_in_year(years):
if years % 4 == 0 and years % 100 != 0 or years % 400 == 0:
return 366
else:
return 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,8 +13,13 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
pass
text_list = text.casefold().replace("(", "").replace(",", "").replace("[", "").replace(" "," ").split(" ")
set_text = set(text_list)
string_vocab = str()
for i in vocab:
string_vocab +=i.lower()+" "
vocab_list = string_vocab.replace(",", "").split(" ")
return list(set(text_list) - set(vocab_list))
def tests(f):

View File

@ -6,8 +6,23 @@ Napisz funkcję sum_from_one_to_n zwracającą sume liczb od 1 do n.
Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
"""
def sum_from_one_to_n(n):
pass
if n>=0:
return n*(n+1)/2
else:
return 0
"""
def sum_from_one_to_n(n):
if n>=0:
suma = 0
for i in range(n):
suma+=i+1
return suma
else:
return 0
def tests(f):

View File

@ -9,8 +9,10 @@ trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
import math
def euclidean_distance(x, y):
pass
return math.sqrt(pow(x[0]-y[0],2)+pow(x[1]-y[1],2)+pow(x[2]-y[2],2))
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,7 +10,10 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
pass
if n>=5:
return "N"+"O"*n+"!"
else:
return "It's not a Big 'No!'"
def tests(f):
inputs = [[5], [6], [2]]

View File

@ -6,7 +6,11 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
def char_sum(text):
pass
suma = 0
for i in text:
suma+=ord(i)
return suma
def tests(f):
inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,7 +7,11 @@ przez 3 lub 5 mniejszych niż n.
"""
def sum_div35(n):
pass
suma = 0
for i in range(n-1):
if (i+1) % 3 == 0 or (i+1) % 5 == 0:
suma+=i+1
return suma
def tests(f):
inputs = [[10], [100], [3845]]

View File

@ -9,7 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
pass
return text.replace("e","3").replace("l","1").replace("o","0").replace("t","7")
def tests(f):

View File

@ -9,7 +9,13 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
text2= str()
for i, t in enumerate(text):
if i % 2 == 0:
text2 += t.upper()
else:
text2 += t
return text2
def tests(f):

View File

@ -9,8 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
return sorted(list(set(string1).intersection(set(string2)).difference(set(" "))))
def tests(f):
inputs = [["this is a string", "ala ma kota"]]

View File

@ -3,9 +3,6 @@
def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
return a + b
def tests(f):