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 trial

Python Introducing Lists Meet Lists Indexing

Servicios Adquiridos SA de CV
Servicios Adquiridos SA de CV
886 Points

SyntaxError while starting the exercise :(

I started to work in the exercise and the next step was write python -i wishlist.py to get the interactive console. But when I do it, it turns out I got a SytanxError invalid syntax I typed exactly how the video says!!

It's hard to say what happened without seeing the code, but it does appear there is a mistake in wishlist.py. Normally python will tell you the line where the mistake is, so I would take a close look at that. Also it should show you the line. Sometimes it is guessing where the actual problem is, so be sure to check before where it reports the problem.

You may want to simply select the text in the teachers notes, and copy it into the file.

4 Answers

Swan The Human
seal-mask
.a{fill-rule:evenodd;}techdegree
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

Try going through the areas or lines that the syntax error is coming up and deleting the white space before the code and then re tabbing it. For some reason if you copy and paste or move your code around certain ways it’ll throw errors. This happens in challenges a lot too. Not sure why but it does.

Another option you could try is to run your code in an actual text editor such as sublime or the actual python program and see if it throws the same syntax error.

I am having the same problem. It is telling me that the problem is on line 4, however, there are only 3 lines. Here is my code:

books = ["Automate the Boring Stuff with Python: Practical Programming for Total Beginners - Al Sweigart", "Python for Data Analysis - Wes McKinney", "Fluent Python: Clear, Concise, and Effective Programming - Luciano Ramalho", "Python for Kids: A Playful Introduction To Programming - Jason R. Briggs", "Hello Web App: Learn How to Build a Web App - Tracy Osborn",]

print("Suggested gift: {}".format(books([0]))

Brandon: it is always helpful to use Markdown to format your code, otherwise it doesn't always show the code the way you intended. When you are writing your comment, just look at the "Markdown Cheatsheet" for advice.

In your program, I think the problem is that you are missing a closing parenthesis. Look at the print line closely.

The reason it is telling you the wrong line is probably that it doesn't know if you intended to continue the print call over multiple lines. It just knows that it got to the end of the file and there was no closing parenthesis to end the print command.

That is a common problem when debugging programs. If you are ever told there is an error on a particular line, and you can't find anything wrong on that line, start reading backwards. Often the problem was a line or two back, but python (or whatever programming language) didn't know for sure there was a problem until it read further.

Okay, great! I will use the Markdown Cheatsheet next time for sure and you're right about that parenthesis. Thank you!