A
A
avion2018-08-28 13:12:57
Python
avion, 2018-08-28 13:12:57

Encoding in Pycharm?

Hello, Pycharm throws an error when using Cyrillic.
 The code:

print("Вычисление НОД")

first_num = int(input("Введите первое число: "))
second_num = int(input("Введите второе число: "))


def NOD(x, y):
    while y != 0:
        x, y = y, x % y
    return x


print("НОД =", NOD(first_num, second_num))

Mistake:
File "/Users/danielkopetskiy/PycharmProjects/PROGRAM_SPB/NOD.py", line 2
SyntaxError: Non-ASCII character '\xd0' in file /Users/danielkopetskiy/PycharmProjects/PROGRAM_SPB/NOD.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Although the setting is set to utf-8 encoding.
What's the problem?
PS
Probyval # coding=utf-8
The first two lines output normally, but the last - no
Вычисление НОД
Введите первое число: 4
Введите второе число: 5
('\xd0\x9d\xd0\x9e\xd0\x94 =', 1)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fixid, 2018-08-28
@Fixid

At the very beginning of the file

# -*- coding: utf-8 -*-
# !/usr/bin/env python

E
Eugene, 2018-08-28
@immaculate

It's not PyCharm, but the Python interpreter. Switch to Python 3 already, utf-8 is assumed by default.

V
Vladimir, 2018-08-28
@vintello

# -*- coding: utf-8 -*-
print(u"Вычисление НОД")

first_num = int(input(u"Введите первое число: "))
second_num = int(input(u"Введите второе число: "))


def NOD(x, y):
    while y != 0:
        x, y = y, x % y
    return x


print(u"НОД = {0}".format( NOD(first_num, second_num)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question