-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy path2_files.py
More file actions
28 lines (20 loc) · 968 Bytes
/
Copy path2_files.py
File metadata and controls
28 lines (20 loc) · 968 Bytes
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
"""
Домашнее задание №2
Работа с файлами
1. Скачайте файл по ссылке https://www.dropbox.com/s/sipsmqpw1gwzd37/referat.txt?dl=0
2. Прочитайте содержимое файла в перменную, подсчитайте длинну получившейся строки
3. Подсчитайте количество слов в тексте
4. Замените точки в тексте на восклицательные знаки
5. Сохраните результат в файл referat2.txt
"""
def main():
with open('referat.txt', 'r', encoding='utf-8') as f:
text = f.read()
words = text.split()
print('Длина строки:', len(text))
print('Количество слов:', len(words))
text = text.replace('.', '!')
with open('referat2.txt', 'w', encoding='utf-8') as f:
f.write(text)
if __name__ == "__main__":
main()