/
sejeenn
/
python_basic
Обзор
Документация
Войти
/
sejeenn
/
python_basic
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Module22/06_paranoia/main.py
31 строка
873 B
Eugene Vorontsov
Copy repo python basic
03 фев 2025, 20:23
03 фев 2025, 20:23
a8fce4a
Код
Авторство
О чём код?
def caesar_cipher(string, user_shift): string = string.lower() char_list = [(alphabet[(alphabet.index(symbol) + user_shift) % 26] if symbol != ' ' else ' ') for symbol in string] new_str = '' for i_char in char_list: new_str += i_char return new_str alphabet = 'abcdefghijklmnopqrstuvwxyz' file_read = open('text.txt', 'r') file_record = open('cipher_text.txt', 'w') print('Содержимое файла text.txt:') print(file_read.read()) shift = 1 file_read = open('text.txt', 'r') for message in file_read: output_str = caesar_cipher(message.join(message.split()), shift) shift += 1 file_record.write(output_str.title() + '\n') file_record.close() file_read.close() new_file_read = open('cipher_text.txt', 'r') print('\nСодержимое файла cipher_text.txt:') print(new_file_read.read()) new_file_read.close()