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

HW_002_uai #3

Open
wants to merge 8 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
51 changes: 48 additions & 3 deletions homework/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime


def test_leap_year():
"""
Задание: необходимо реализовать функцию is_leap_year, принимающую на вход объект типа datetime.date
Expand All @@ -12,7 +11,16 @@ def test_leap_year():
"""

def is_leap_year(date):
pass
if date.year % 100 == 0:
if date.year % 400 == 0:
return True
else:
return False
else:
if date.year % 4 == 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 @@ -22,6 +30,8 @@ def is_leap_year(date):
assert not is_leap_year(datetime.date(year=2001, month=10, day=15))




def test_file_data():
"""
Задание: необходимо реализовать функцию, которая принимает filename - имя текстового файла и переменную word,
Expand All @@ -33,8 +43,43 @@ def test_file_data():
"""

def count_word_in_file(filename, word):
pass
myFileLists = []
myFileWords = []
fileWord = ''
count = 0
with open(filename, encoding="utf-8") as myFile:

"dividing the text into lines and replacing \n to ' '"
for line in myFile:

#line = line.lower().replace('\n', ' ')
#line = line.replace('\n', ' ')

myFileLists.append(line.lower().replace('\n', ' '))


'dividing lines into words'
for fileList in myFileLists:
for fileListLetter in fileList:
if fileListLetter != ' ':
fileWord += fileListLetter
else:
myFileWords.append(fileWord)
fileWord = ''


'finding the word'
for words in myFileWords:
if words == word:
count += 1


myFile.close()

return count


assert count_word_in_file("homework/pony.txt", "радуга") == 0
assert count_word_in_file("homework/pony.txt", "и") == 3
assert count_word_in_file("homework/pony.txt", "пони") == 5