[英]SyntaxError with print
The code in the interactive shell:交互式 shell 中的代码:
>>>password = ''
>>>while password != 'secret':
password = input('Please password')
print("Right password")
SyntaxError: invalid syntax
>>>
I want to make a code where he will ask me to enter the code and i can do it... But when i press enter I get the following message.我想制作一个代码,他会要求我输入代码,我可以做到...但是当我按 Enter 时,我收到以下消息。
python3蟒蛇3
Please note input() and print() in Python2.x is a little different with python3.x请注意 Python2.x 中的 input() 和 print() 与 python3.x 略有不同
Therefore, Check your python version first.因此,首先检查您的 python 版本。
Python2.x: Python2.x:
password = raw_input('prompt to user')
print 'hello world'
Python3.x: 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.然后,当您在命令行中定义一个while循环时,您应该将一行留空并在while循环完成后按Enter ,输入您的代码的rest。
As I showed in the above picture, I left a line empty then press enter
, then I entered my rest of codes.如上图所示,我留了一行空白然后按enter
,然后我输入了我的 rest 代码。
If you wanna run your code in Python v3
, in the command prompt or Linux shell enter: python3如果您想在Python v3
中运行代码,请在命令提示符或Linux shell 中输入:python3
If you got error please download the latest version of python如果出现错误,请下载最新版本的 python
Finally, as others say, please use an IDE like vscode
and enter your entire code then run it, less trouble!!!最后,正如其他人所说,请使用像 vscode 一样的vscode
并输入您的整个代码然后运行它,少麻烦!
Download VisualStudio Code:下载 VisualStudio 代码:
( https://code.visualstudio.com/download ). ( https://code.visualstudio.com/download )。
Python shell doesn't support the complex code. Python shell 不支持复杂代码。 Maybe You can try this.也许你可以试试这个。
Python shell with while
Python shell with while
Anyway, I recommend you to use the script.无论如何,我建议您使用该脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.