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 trialGard Sveipe Bahmanyar
1,693 PointsCould someone explain why its 2,3,4,5,6 and not 2,4,6,8 when it is +2 in the function?
Could someone explain?
3 Answers
Blaize Pennington
13,879 Pointsfor num in range(10):
print(add_two(num))
This code is literally saying for every number in the range of 10 (range starts at 0 and ends before the number so 9.)
So this will create a loop that enters each of these.
print(add_two(0)) // 0 + 2 = 2
print(add_two(1)) // 1 + 2 = 3
print(add_two(2) // 2 + 2 = 4
print(add_two(3)) // 3 + 2 = 5
etc
Leah Kelly
4,141 Pointsanother thing: 10 + 2 isn't on there because range() does everything BEFORE the number inside it.
Benja Guzzetta
2,447 PointsI totally agree with Ashley.. I have no idea wtf the purpose of this function would be. I mean I understand what it does.. but it seems useless for actual programming. Hopefully it will make more sense the more I learn, but I can think of no situation where this particular function has a place.
Jeffery Jones
2,769 PointsJeffery Jones
2,769 PointsThis was very helpful since range has not been explained in the videos yet. Thanks!!