exd3/script.py

30 lines
1.2 KiB
Python
Raw 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.

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()