Zadanie A03

This commit is contained in:
s450026 2020-11-08 17:45:41 +01:00
parent 07c719be98
commit d0af982a3e
2 changed files with 47 additions and 0 deletions

45
TaskA03/A03.py Normal file
View File

@ -0,0 +1,45 @@
import sys
def check_date(word):
try:
date = int(word)
if 1900 <= int(date) <= 1999:
return True
else:
return False
except ValueError:
return False
def check_words(words):
all_dates = []
for word in words:
if check_date(word):
all_dates.append(word)
return all_dates
def contains_date(line):
formatted_line = line.lower()
words = formatted_line.split()
for word in words:
if '.' in word:
words.extend(word.split('.'))
if '(' in word:
words.extend(word.split('('))
if ')' in word:
words.extend(word.split(')'))
checked_dates = check_words(words)
for date in checked_dates:
if checked_dates:
if date + ' r.' in formatted_line:
return line
else:
return False
for line in sys.stdin:
if contains_date(line):
print(line.rstrip("\n"))

2
TaskA03/run Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
python3 TaskA03/A03.py "$@"