Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialArun Shivaramakrishna
4,771 PointsUnable to understand the cause of File "<stdin>" error
name = input("what is your name? ")
if name == "ABC": print (name + "is learning python and is a lumberjack") else: print(name + "already knows python")
5 Answers
William Li
Courses Plus Student 26,868 PointsLooks like you're trying to run the Python script while inside the Python REPL. No, you can't do that.
First, you have to exit the Python REPL by entering exit()
, then you can run the script with python lumberjack.py
tootiemcflow
5,601 PointsYou have a space in your first print statement print (name + "is learning python and is a lumberjack")
directly after the word print in the if/else block.
name = input("what is your name? ")
if name == "ABC":
print(name + "is learning python and is a lumberjack")
else:
print(name + "already knows python")
Arun Shivaramakrishna
4,771 PointsI changed that , but i still get the below error
python lumberjack.py
File "<stdin>", line 1
python lumberjack.py
^
SyntaxError: invalid syntax
Arun Shivaramakrishna
4,771 PointsThe same error still persists
exit()
treehouse:~/workspace$ python
Python 3.4.1 (default, Mar 16 2015, 15:20:22)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
python lumberjack.py
File "<stdin>", line 1
python lumberjack.py
^
SyntaxError: invalid syntax
William Li
Courses Plus Student 26,868 PointsHey Arun, you exit the REPL with exit()
, then you enter REPL again with python
command, don't do that, please, that'd only take you back to square one.
exit()
python lumberjack.py
that's all.
You command prompt has to be showing treehouse:~/workspace$, this is the indication that you're not in the Python REPL, then you can run the script by entering python lumberjack.py
.
Arun Shivaramakrishna
4,771 PointsThanks William, Got it!