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

python question, invalid syntax error, when typing in the console python -i expenses.py or python expenses.py

travel_expenses = [
    [5.00, 2.75, 22.00, 0.00, 0.00],
    [24.75, 5.50, 15.00, 22.00, 8.00],
    [2.75, 5.50, 0.00, 29.00, 5.00],
]

print("Travel Expenses:")
week_number = 1
for week in travel_expenses:
      print("* Week #[]:".format(week_number, sum(week)))
      week_number +=1

Moderator edited: Markdown added so that code renders properly in the forums. -jn

What's the error?

the error is a invalid syntax error when putting a command in the console to call the program

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Simran Bansari ! I'm not sure why exactly you're getting the syntax error. Are you doing this in workspaces? When I run it in workspaces, I get no syntax error. This makes me think that perhaps you're doing it on your local system and may be running a different version of Python.

I do see a couple of oddities though. First, you have an extraneous comma in your multidimensional array after the last sub-array. Secondly, your print statement should have two sets of curly braces {}, instead of the one set of square brackets []. I took the liberty of reworking your code so it works like I think you're expecting.

travel_expenses = [
    [5.00, 2.75, 22.00, 0.00, 0.00],
    [24.75, 5.50, 15.00, 22.00, 8.00],
    [2.75, 5.50, 0.00, 29.00, 5.00]
]

print("Travel Expenses:")
week_number = 1
for week in travel_expenses:
      print("* Week #{}: {}".format(week_number, sum(week)))
      week_number +=1

Hope this helps! :sparkles: