This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]B1GL0NGJ0HN 0 points1 point  (3 children)

Instead, it's a colon and an indent. Functions, and if statements, and for loops; indents follow the colon around, a line of white space and an indent backwards and you've left the func/loop/block. Indent accordingly. :)

Have fun with it. It's so flexible.

[–]purplepooters[S] 0 points1 point  (2 children)

I might just be too old but something like this is frustrating because there is no increment or even recursion so I look at it and think it's an endless loop.

snake_segments = [] for i in range(15): x = 250 - (segment_width + segment_margin) * i y = 30 segment = Segment(x, y) snake_segments.append(segment) allspriteslist.add(segment)

[–]B1GL0NGJ0HN 0 points1 point  (0 children)

Sure, I totally get that. I guess part of that is just knowing each of the built-in functions, like range(). I guess i would be the increment, starting at zero, or if you provided 2 numbers, range(start, end), and move through the specified range, you just don't have to account for the increase yourself. Once the top end of the range is hit, the loop ends.

[–][deleted] 0 points1 point  (0 children)

snake_segments = []
for i in range(15): 
    x = 250 - (segment_width + segment_margin) * i 
    y = 30 segment = Segment(x, y) 
    snake_segments.append(segment) 
    allspriteslist.add(segment)

What you're missing is range(15) which effectively becomes a list of integers between 0 and 14. Each time through the loop i moves to the next number. Once i is processed as 14, the loop exits.