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 Using Lists Multidimensional Lists

Why we put increment in the end of loop.It is necessary?

For example: 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)))

In this program without increment the output is Travel Expenses:

  • week #1: $29.75
  • week #2: $75.25
  • week #3: $42.25 >>> and with increment the output is also the same,There is no difference in result.Is it necessary to put the increment every time?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

The increment is necessary. When I run the code without the increment, I get:

Travel Expenses:
* week #1: $29.75
* week #1: $75.25
* week #1: $42.25

perhaps you weren't running the code you thought?

Post back if you need more help. Good luck!!