1
0
forked from tdwojak/Python2017

ready for review

This commit is contained in:
s45155 2017-11-25 18:06:51 +01:00
parent cd6b55c938
commit 2386b38ffe
11 changed files with 64 additions and 18 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,15 @@
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 and year % 400 == 0:
return 366
elif year % 4 == 0 and year % 100 != 0:
return 366
elif year % 4 == 0 and year % 100 == 0 and year % 400 != 0:
return 365
else:
return 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -13,11 +13,11 @@ jak 'set', która przechowuje elementy bez powtórzeń.)
def oov(text, vocab):
s=set()
for i in text.split():
if i not in vocab:
text.lower()
return s
s=set()
for i in text.split():
if i not in vocab:
s.add(i)
return s

View File

@ -7,7 +7,14 @@ 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:
x=0
for i in range (n+1):
x=x+i
return x
def tests(f):

View File

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

View File

@ -10,7 +10,14 @@ 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:
tekst="N"
for i in range (n):
tekst += "O"
tekst += "!"
return(tekst)
def tests(f):
inputs = [[5], [6], [2]]

View File

@ -6,7 +6,10 @@ 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 range (len(text)):
suma+=ord(text[i])
return(suma)
def tests(f):
inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,7 +7,12 @@ 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]]

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,11 +9,18 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
pass
for i in range(len(text)):
if i == 0:
mytext=''.join(['', text[i].upper()])
elif i % 2 == 0:
mytext = ''.join([mytext[:i], text[i].upper()])
else:
mytext = ''.join([mytext[:i], text[i]])
return (mytext)
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):
@ -23,4 +30,4 @@ def tests(f):
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(pokemon_speak))
print(tests(pokemon_speak))

View File

@ -9,7 +9,14 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
s=[]
s1 = list(set(string1.replace(' ','')))
s2 = list(set(string2.replace(' ','')))
for i in s1:
if i in s2:
s.append(i)
s.sort()
return s
def tests(f):