SyntaxError с печатью - PullRequest
       1

SyntaxError с печатью

1 голос
/ 05 августа 2020

Код в интерактивной оболочке:

>>>password = ''
>>>while password != 'secret':
       password = input('Please password')

print("Right password")
SyntaxError: invalid syntax
>>>

Я хочу создать код, в котором он попросит меня ввести код, и я могу это сделать ... Но когда я нажимаю клавишу ввода, я получаю следующее сообщение.

python3

https://imgur.com/a/7z6CaTu

Ответы [ 2 ]

3 голосов
/ 05 августа 2020

Обратите внимание, что input () и print () в Python2 .x немного отличаются от python3 .x Поэтому сначала проверьте версию python.

Shot1

Python2.x:

password = raw_input('prompt to user')
print 'hello world'

Python3.x:

password = input('prompt to user')
print('hello world')

Then, when you define a while loop in the command line, you should leave a line empty and press Enter after while loop completed, enter the rest of your code.

shot2

As I showed in the above picture, I left a line empty then press enter, then I entered my rest of codes.

If you wanna run your code in Python v3, in the command prompt or Linux shell enter: python3
If you got error please download the latest version of python
Finally, as others say, please use an IDE like vscode and enter your entire code then run it, less trouble!!!
Download VisualStudio Code:
(https://code.visualstudio.com/download).

0 голосов
/ 05 августа 2020
Оболочка

Python не поддерживает сложный код. Возможно, вы можете попробовать это.

Python shell с while

В любом случае, я рекомендую вам использовать скрипт.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...