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


While iterating through the list, I don't get the value for the week number and my code prints out the list as well

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:

week_number += 1

print("* Week #{}: ${}".format(week, sum(week)))

my output:


  • Week #[5.0, 2.75, 22.0, 0.0, 0.0]: $29.75
  • Week #[24.75, 5.5, 15.0, 22.0, 8.0]: $75.25
  • Week #[2.75, 5.5, 0.0, 29.0, 5.0]: $42.25

1 Answer

Please view the markdown sheet (located just below where you can type a response).

you do get the sum of for the week but it also returns the list of values for that week because you have put week when you meant to put week_number:

"print(("* Week #{}: ${}".format(week, sum(week)))" should turn into: print("Week #{}: ${}".format(week_number, sum(week))) That should output:

Week #1: <total cost>

Week #2: <total cost>

(There was also an extra open bracket at the start which isn't needed)

Hope this helps.