In Python I put print() but still get a syntax error -


i read answers here print() parentheses. have put them , syntax error anyway. can tell why?

python 3.3.2+ (default, feb 28 2014, 00:52:16)  [gcc 4.8.1] on linux    >>> answer = "no" >>> while answer == "no": ...     answer = input("are there? ") ... print("we're there!")   file "<stdin>", line 3     print("we're there!")         ^ syntaxerror: invalid syntax 

yes, can see ... prompt keeps print line under while loop. if press 2 times enter prints string input.

>>> answer = "no" >>> while answer == "no": ...     answer = input("are there? ") ...  there? 

well since you're in interpreter, can see 3 dots again, means it's still expecting under while loop. press enter again , work. if want print part of loop, indent it, press enter , press enter again. hope helps!

1: >>> answer = "no" 2: >>> while answer == "no": 3: ...     answer = input("are there? ") 4: ...  5: there? no 6: there? yes 7: >>> 

at line 2, start loop. @ line 3, input stdin stored in answer. argument input takes message prompted used. @ line 4, interpreter still expects loop. if have indented block, part of loop. if press enter, finishes loop

note: interpreter , has whole while block can executed, executes.

at line 5, executing loop , waiting input(and has shown correct message)

you enter 'no' input. doesn't break loop executes loop again , asks input again. put 'no' , breaks out , have prompt again interpreter has nothing execute (yet).


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -