-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (55 loc) · 2.13 KB
/
main.py
File metadata and controls
67 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from string import punctuation
LINE_WIDTH = 45
def del_punctuation(value):
for punct in punctuation:
value = value.replace(punct, '')
return value
def clean(text, as_set=True):
clean_text = [del_punctuation(word).lower() for word in text.split() if len(word) > 1]
return set(clean_text) if as_set else clean_text
def count_pred(text):
text = text.replace('...', '.')
count_pred = text.count('.') + text.count('!') + text.count('?')
return count_pred
def print_res(count_pred, count_word, count_sim, unique_word_text, text_num):
print(f'Информация для {text_num} текста:')
print(f'Всего предложений: {count_pred}')
print(f'Всего слов: {count_word}')
print(f'Всего символов: {count_sim}')
print(f'Всего уникальных слов: {len(unique_word_text)}')
print('Уникальные слова:', *unique_word_text if unique_word_text else ['не найдено'])
print('=' * LINE_WIDTH)
print('АНАЛИЗАТОР ТЕКСТА')
print('=' * LINE_WIDTH)
print()
text1 = input('Введите первый текст:\n')
print()
text2 = input('Введите второй текст:\n')
if not text1.strip() or not text2.strip():
print('Внимание! Один из текстов пуст.')
exit()
set_text1 = clean(text1)
set_text2 = clean(text2)
count_pred_text1 = count_pred(text1)
count_pred_text2 = count_pred(text2)
count_word1 = len(clean(text1, False))
count_word2 = len(clean(text2, False))
count_sim1 = len(text1)
count_sim2 = len(text2)
unique_word = set_text1 & set_text2
unique_word_text1 = set_text1 - set_text2
unique_word_text2 = set_text2 - set_text1
print()
print('=' * LINE_WIDTH)
print('РЕЗУЛЬТАТЫ АНАЛИЗА')
print('=' * LINE_WIDTH)
print()
print('Общая информация:')
if unique_word:
print('Общие слова:', *sorted(unique_word), sep=', ')
else:
print('Общих слов не найдено.')
print()
print_res(count_pred_text1, count_word1, count_sim1, unique_word_text1, '1')
print()
print_res(count_pred_text2, count_word2, count_sim2, unique_word_text2, '2')