forked from tdwojak/Python2017
test
This commit is contained in:
parent
d5755b6965
commit
95733aa1aa
22
homework/task07.py
Normal file
22
homework/task07.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
|
||||
sumę kodów ASCII znaków.
|
||||
"""
|
||||
def char_sum(text):
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string"], ["this is another string"]]
|
||||
outputs = [1516, 2172]
|
||||
|
||||
for input, output in zip(inputs, outputs):
|
||||
if f(*input) != output:
|
||||
return "ERROR: {}!={}".format(f(*input), output)
|
||||
break
|
||||
return "TESTS PASSED"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(char_sum))
|
24
homework/task08.py
Normal file
24
homework/task08.py
Normal file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Napisz funkcję sum_div35(n), która zwraca sumę wszystkich liczb podzielnych
|
||||
przez 3 lub 5 mniejszych niż n.
|
||||
"""
|
||||
|
||||
def sum_div35(n):
|
||||
pass
|
||||
|
||||
def tests(f):
|
||||
inputs = [[10], [100], [3845]]
|
||||
outputs = [23, 2318, 3446403]
|
||||
|
||||
for input, output in zip(inputs, outputs):
|
||||
if f(*input) != output:
|
||||
return "ERROR: {}!={}".format(f(*input), output)
|
||||
break
|
||||
return "TESTS PASSED"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(sum_div35))
|
||||
|
26
homework/task09.py
Normal file
26
homework/task09.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Napisz funkcję leet_speak, która podmienia w podanym napisie niektóre litery
|
||||
na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'.
|
||||
Np. leet('leet') powinno zwrócić '1337'.
|
||||
"""
|
||||
|
||||
|
||||
def leet_speak(text):
|
||||
pass
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [['leet'], ['do not want']]
|
||||
outputs = ['1337', 'd0 n07 wan7']
|
||||
|
||||
for input, output in zip(inputs, outputs):
|
||||
if f(*input) != output:
|
||||
return "ERROR: {}!={}".format(f(*input), output)
|
||||
break
|
||||
return "TESTS PASSED"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(leet_speak))
|
26
homework/task10.py
Normal file
26
homework/task10.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""
|
||||
Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą literę
|
||||
na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
|
||||
"""
|
||||
|
||||
|
||||
def pokemon_speak(text):
|
||||
pass
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
|
||||
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
|
||||
|
||||
for input, output in zip(inputs, outputs):
|
||||
if f(*input) != output:
|
||||
return "ERROR: {}!={}".format(f(*input), output)
|
||||
break
|
||||
return "TESTS PASSED"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(pokemon_speak))
|
26
homework/task11.py
Normal file
26
homework/task11.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""
|
||||
Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie
|
||||
uporządkowaną listę wspólnych liter z lańcuchów string1 i string2.
|
||||
Oba napisy będą składać się wyłacznie z małych liter.
|
||||
"""
|
||||
|
||||
def common_chars(string1, string2):
|
||||
pass
|
||||
|
||||
|
||||
def tests(f):
|
||||
inputs = [["this is a string", "ala ma kota"]]
|
||||
outputs = [['a', 't']]
|
||||
|
||||
for input, output in zip(inputs, outputs):
|
||||
if f(*input) != output:
|
||||
return "ERROR: {}!={}".format(f(*input), output)
|
||||
break
|
||||
return "TESTS PASSED"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(common_chars))
|
@ -8,7 +8,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
|
||||
|
||||
def even_elements(lista):
|
||||
pass
|
||||
|
||||
return lista[::2]
|
||||
|
||||
def tests(f):
|
||||
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
||||
|
@ -5,8 +5,14 @@
|
||||
Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366).
|
||||
"""
|
||||
|
||||
def days_in_year(days):
|
||||
def days_in_year(year):
|
||||
pass
|
||||
if year % 400 == 0:
|
||||
return 366
|
||||
elif year % 4 == 0 and year % 100 != 0:
|
||||
return 366
|
||||
else:
|
||||
return 365
|
||||
|
||||
def tests(f):
|
||||
inputs = [[2015], [2012], [1900], [2400], [1977]]
|
||||
|
@ -11,12 +11,18 @@ litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
|
||||
jak 'set', która przechowuje elementy bez powtórzeń.)
|
||||
"""
|
||||
|
||||
text = "this is a string , which i will use for string testing"
|
||||
vocab = [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i']
|
||||
|
||||
def oov(text, vocab):
|
||||
pass
|
||||
temp_text=text.split(' ')
|
||||
temp_vocab=vocab.split(' ')
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
def tests(f):
|
||||
inputs = [("this is a string , which i will use for string testing",
|
||||
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
|
||||
@ -30,3 +36,4 @@ def tests(f):
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(tests(oov))
|
||||
"""
|
@ -7,6 +7,7 @@ def suma(a, b):
|
||||
Napisz funkcję, która zwraca sumę elementów.
|
||||
"""
|
||||
pass
|
||||
return a + b
|
||||
|
||||
def tests(f):
|
||||
inputs = [(2, 3), (0, 0), (1, 1)]
|
||||
|
Loading…
Reference in New Issue
Block a user