(python) ОШИБКА: попытка использования x = input ("строка") вызывает ошибки - PullRequest
0 голосов
/ 05 мая 2020
Traceback (most recent call last):
File "p.py", line 1, in <module>
x = input("hello")
File "<string>", line 0  

SyntaxError: unexpected EOF while parsing

Я получаю эту ошибку, когда ввожу в свой скрипт следующий код:

x = input("press enter to continue")

и то же самое, когда я ввожу это:

input("press enter to continue")

и снова:

input('press enter to continue')

Я использую linux на chrome acer с linux beta. он использует python 3. что не так?

Ответы [ 2 ]

0 голосов
/ 05 мая 2020

Я считаю, что вы используете Python 2, а не Python 3. Замените input на raw_input:

x = raw_input("press enter to continue")


Вот почему Я считаю, что вы используете Python 2. Мой тест с Python 3 (обратите внимание, что ошибки нет):

Python 3.7.6
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("press enter to continue")
press enter to continue
>>>

И затем я вижу ту же ошибку, что и при использовании Python 2 :

Python 2.7.17
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("press enter to continue")
press enter to continue
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 0

    ^
SyntaxError: unexpected EOF while parsing
>>> x = raw_input("press enter to continue")
press enter to continue
>>>
0 голосов
/ 05 мая 2020

Попробуйте raw_input () вместо input ()

...