H
H
hardwellZero2015-02-12 17:07:15
Python
hardwellZero, 2015-02-12 17:07:15

How to make Python output Russian text?

What needs to be done so that the Cyrillic alphabet is displayed in the console?
For English. alphabet - works, but for Russian - no.

__author__ = 'getlucky'
# -*- coding: utf-8 -*-
def cesarMethod(message):
    output = []
    alphabet = 'abcdefghijklmnopqrstuvwxyz'#'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
    steps = int(raw_input('Введите Ваш ключ: '))

    for i in message:
        if i == ' ':
            output.append(' ')
        else:
            pos = alphabet.index(i) + steps
            if pos >= 25:
                pos -= 26
            output.append(alphabet[pos].decode('utf8'))

    print 'Зашифрованное сообщение: ', ''.join(output)

message = raw_input('Введите Ваше сообщение: ').lower()
cesarMethod(message)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oscar Django, 2015-02-12
@hardwellZero

# -*- coding: utf-8 -*-
message = 'ывпавыапавыпвпав'
for i in message:
        print(i)

compare output with
message = u'ывпавыапавыпвпав'
for i in message:
        print(i)

only one character difference
UPDATE
# -*- coding: utf-8 -*-
def cesarMethod(message):
    output = []
    # alphabet = 'abcdefghijklmnopqrstuvwxyz'#'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
    alphabet = u'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
    # steps = int(raw_input('Введите Ваш ключ: '))
    steps = 2

    for i in message.decode('utf8'):
        if i == ' ':
            output.append(' ')
        else:
            pos = alphabet.index(i) + steps
            if pos >= 25:
                pos -= 26
            output.append(alphabet[pos])

    print 'Зашифрованное сообщение: ', ''.join(output)

# message = raw_input('Введите Ваше сообщение: ').lower()
message = 'специальнодлятостера'

cesarMethod(message)

A
Anton Fedoryan, 2015-02-12
@AnnTHony

Save the file in UTF-8 encoding

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question