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

leap_year #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions homework/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import re


def test_leap_year():
Expand All @@ -12,7 +13,11 @@ def test_leap_year():
"""

def is_leap_year(date):
pass
a = date.year
if (((a % 400) == 0) or (((a % 4) == 0) and ((a % 100) != 0))):
return True
else:
return False

assert is_leap_year(datetime.date(year=2000, month=5, day=13))
assert is_leap_year(datetime.date(year=2016, month=11, day=1))
Expand All @@ -33,7 +38,13 @@ def test_file_data():
"""

def count_word_in_file(filename, word):
pass
num = 0
with open(filename) as u:
for line in u:
text_words = list(re.findall(r'\w+', line.casefold())) #ищем слова
num += text_words.count(word)
u.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

u нет нужды здесь закрывать - контекстный менеджер (with) сделает это самостоятельно.

return num

assert count_word_in_file("homework/pony.txt", "радуга") == 0
assert count_word_in_file("homework/pony.txt", "и") == 3
Expand Down