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 trialIrfan Sattar
600 PointsFile "<stdin>", line 1 error when running script
After I type the script and go to the console to run the script I get this error:
python lumberjack.py File "<stdin>", line 1 python lumberjack.py ^ syntaxError: invalid syntax
This is my code:
name = input("What's your name? ")
if name == "Irfan": print(name + " is a lumberjack and he's okay!") else: print(name + "sleeps all night and " + name + " works all day!")
5 Answers
Parker Skiba
5,583 PointsHmm i ran your code in the workspace and It ran fine... Try just typing
python lumberjack.py
also check that you have saved your file and that your filename is in fact lumberjack.py
John Matulich
6,607 PointsI had this problem as well, then I realized I was still in the python interpreter.
I typed:
exit()
then at the workspace prompt:
python lumberjack.py
and it worked properly.
Danielle Abelard
209 PointsSame for me, also got it when I tried opening python on a separate line from opening the file.
Kenneth Love
Treehouse Guest TeacherDanielle Abelard so was your problem the same as johnmatulich? You were trying to run a Python script from inside the Python shell?
someguy1234
3,450 PointsWow, thank you! I get it now. I need to get out of the python shell first to run a script!
Irfan Sattar
600 PointsHm, I reopened the workspace and it worked fine this time. Must just be some bug with the workspace because before I had it saved too and typed the same thing you told me to but it gave that error before. Thanks!
Juan de Elena O'Shea
4,757 PointsHello! Just my 0.02$: I tried meddling around with the default indentation, and anything besides Spaces 2 seems to lead to the <stdin> syntax error.
Kenneth Love
Treehouse Guest TeacherSo long as the spacing is consistent, Python doesn't care the number of spaces.
Kevin McFarland
5,122 PointsI also had errors... I stumpled upon "Check Module" under the Run menu and it showed an indentation error. I'm also using the Python 3.4.2 script editor.