Nikaiwths
Nikaiwths

Reputation: 11

SyntaxError with print

The code in the interactive 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.

python3

https://i.sstatic.net/X9rv1.jpg

Upvotes: 1

Views: 199

Answers (2)

Peyman Majidi
Peyman Majidi

Reputation: 1985

Please note input() and print() in Python2.x is a little different with python3.x
Therefore, Check your python version first.

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).

Upvotes: 6

jiangNan langzi
jiangNan langzi

Reputation: 39

Python shell doesn't support the complex code. Maybe You can try this.

Python shell with while

Anyway, I recommend you to use the script.

Upvotes: -1

Related Questions