Skip to content

Instantly share code, notes, and snippets.

@not7cd
Last active February 6, 2019 14:54
Show Gist options
  • Save not7cd/f11fadfb4e6edecfa6da0e7a21d40157 to your computer and use it in GitHub Desktop.
Save not7cd/f11fadfb4e6edecfa6da0e7a21d40157 to your computer and use it in GitHub Desktop.
Recrutiment task
from decimal import Decimal
def postal_code_gen(min_code, max_code):
"""
>>> list(postal_code_gen("79-995", "80-003"))
["79-996", "79-997", "79-998", "79-999", "80-000", "80-001", "80-002"]
"""
# Napisanie generatora prosiło się o napisanie generatora który używa yield a nie zwraca listy
min_num = int(min_code.replace("-", ""))
max_num = int(max_code.replace("-", ""))
if min_num > max_num:
raise ValueError("min_code bigger than max_code")
if max_num >= 100000:
raise ValueError("max_code too big")
for num in range(min_num + 1, max_num ):
yield "{:06,}".format(num).replace(",", "-")
def task_1(min_code, max_code):
"""
ZADANIE 1. Napisz generator kodów pocztowych, który przyjmuje 2 stringi: "79-900" i "80-155"
i zwraca listę kodów pomiędzy nimi.
"""
return list(postal_code_gen(min_code, max_code))
def task_2(elements, n):
"""
ZADANIE 2. Podana jest lista zawierająca elementy o wartościach 1-n.
Napisz funkcję, która sprawdzi, jakich elementów brakuje:
>>> task_2([2, 3, 7, 4, 9], 10)
[1, 5, 6, 8, 10]
"""
whole_set = set(range(1, n+1))
return list(whole_set - set(elements))
def frange(x, y, jump):
while x <= y:
yield x
x += jump
def task_3():
"""
ZADANIE 3. Należy wygenerować listę liczb od 2 do 5.5 ze skokiem co 0.5.
Dane wynikowe muszą być typu decimal.
"""
return list(frange(Decimal(2.), Decimal(5.5), Decimal(0.5)))
if __name__ == '__main__':
print(task_1("79-900", "80-155"))
print(task_2([2,3,7,4,9], 10))
print(task_3())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment