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 trialAizah Sadiq
2,435 PointsWhy do we put week_number += 1
What does week_number += 1 do
2 Answers
Mark Sebeck
Treehouse Moderator 37,799 PointsIt takes the value stored in week_number and adds 1 to it then stores the new value in week_number. Itβs the same as week_number = week_number + 1
Piotr Sochaczewski
13,038 PointsI would like to know - why there isn't an infinity loop? ...
- Week #4: $0
- Week #5: $0 and so on?
This is what I don't get - why the program stopped :) (It's good but why?) I ask because in JS we should make some condition like i=0, i < travel_expenses.length and i+=1 but in python, we don't have any condition just +=1
Mark Sebeck
Treehouse Moderator 37,799 PointsHi Piotr. Good question. It is because the for in loop automatically loops through the list or array. In this case the i+=1 is only incrementing i to print the week number.