basicsPython/less-05/task-04.py
2022-03-19 14:55:20 +03:00

23 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Создать (не программно) текстовый файл со следующим содержимым:
#
#One — 1
#Two — 2
#Three — 3
#Four — 4
#
#Напишите программу, открывающую файл на чтение и считывающую построчно данные.
#При этом английские числительные должны заменяться на русские.
#Новый блок строк должен записываться в новый текстовый файл.
file_name = 'examples5/text_4.txt'
dig = {'One':'Один', 'Two':'Два', 'Three':'Три', 'Four':'Четыре', 'Five':'Пять',
'Six':'Шесть', 'Seven':'Семь', 'Eight':'Восемь', 'Nine':'Девять',}
with open(file_name, "r", encoding='utf-8') as fr, open("task04.txt", "w", encoding='utf-8') as fw:
for line in fr:
eng, sep, num = line.split()
# print(f'{dig[eng]} {sep} {num}')
print(f'{dig[eng]} {sep} {num}', file=fw)