Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

№22 #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions homework/tests.py → homework/№22
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def test_even_fucntion():
"""

def even_filter(*args):
pass
return[i for i in args if i % 2 == 0]

assert even_filter(1, 2, 3, 4, 5, 6) == [2, 4, 6]

Expand All @@ -16,12 +16,13 @@ def test_increment_decorator():
декрорируемую функцию.
"""
def increment_derocator(func):
pass

def wrapper(value):
func(value+1)
return wrapper

@increment_derocator
def returner(value):
return value

assert returner(1) == 2


Expand All @@ -40,12 +41,16 @@ def __init__(self, x, y):


class Segment():
def __init__(self, p1, p2):
pass

def length(self):
return 0

def __init__(self, p1, p2):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass больше не нужен - у нас уже появился код для метода __init__

self.p1 = p1
self.p2 = p2

def length(self):

length = math.hypot(self.p1.x - self.p2.x, self.p1.y - self.p2.y)

return length
p1 = Point(0, 0)
p2 = Point(3, 4)
assert Segment(p1, p2).length() == 5.0
Expand All @@ -72,7 +77,14 @@ def test_translate():
Документация по этому методу: https://docs.python.org/3/library/stdtypes.html#str.join
"""
def translate(fraze, dictionary):
pass
def translate(fraze, dic):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Второе объявление функции не нужно (речь о внутренней def translate(fraze, dic):)

def translate(fraze, dictionary):
    def translate(fraze, dic):

i = fraze.split()
Num = len(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Num, Tran, Translate - не python-стиль. Стоит переименовать в num, т.к. CamelCase закреплен за именами классов.
  2. Не обязательно итерироваться по индексам элементов в списке, можно сразу по этим элементам итерироваться:
split_fraze = fraze.split()
for word in split_fraze:
    tran.append(dic[word])

Tran=[]
for a in range(Num):
Tran.append(dic[i[a]])
Translate = " ".join(Tran)
return Translate

assert translate("hello world", {"hello": "привет", "world": "мир"}) == "привет мир"
assert translate("привет мир", {"привет": "hello", "мир": "world"}) == "hello world"
Expand All @@ -93,7 +105,7 @@ def test_is_prime():
"""

def is_prime(n):
pass

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Без тела функции будет синтаксическая ошибка. Нужно либо pass вернуть, либо добавить код для фукнции.


assert is_prime(2)
assert is_prime(3)
Expand Down