Проверил что добавились только файлы data.txt и script.py

This commit is contained in:
Григорий Горочный 2025-03-04 21:54:56 +03:00
parent 7b93f8f824
commit 81d44afc06
2 changed files with 29 additions and 0 deletions

0
data.txt Normal file
View File

29
script.py Normal file
View File

@ -0,0 +1,29 @@
def main():
# Запрашиваем у пользователя выбор
choice = input("Введите 'u' для перевода в верхний регистр или 'l' для перевода в нижний регистр: ").strip().lower()
# Читаем содержимое файла data.txt
try:
with open('data.txt', 'r', encoding='utf-8') as infile:
data = infile.read()
except FileNotFoundError:
print("Файл data.txt не найден.")
return
# Преобразуем текст в зависимости от выбора пользователя
if choice == 'u':
output_data = data.upper()
elif choice == 'l':
output_data = data.lower()
else:
print("Некорректный ввод. Пожалуйста, введите 'u' или 'l'.")
return
# Записываем преобразованный текст в файл output.txt
with open('output.txt', 'w', encoding='utf-8') as outfile:
outfile.write(output_data)
print("Результат записан в файл output.txt")
if __name__ == "__main__":
main()