Close. The for-loop expects an iterable of pairs, so you’d need a function which pairs up those two ranges:
zip(range(1, 7), range(10, 5, -1))
Or if you have some better way to create pairs, because that’s slightly messy/difficult to read. In this particular case the numbers always have a sum of 11, so you could also compute one number from the other… Exactly how you decide to write it comes down to good taste really… There will be many ways to express it, and what those ways are depends on what you’re describing
(you need something that looks like this: [(1, 2), (3, 4)], to be unpacked one pair at a time )
In actual program, I wanted one column to start at 40, decrease by 1 all the way to 31 and the second column starts at 120 and goes down by 10 all the way to 30
for offset in range(10):
c1 = 40 - offset
c2 = 120 - offset * 10
…But I might do it differently understanding the whole situation. In the end, you should go with whatever looks best to you, and it can be hard to come up with a “best” without having seen lots of other code to draw inspiration from.
Either you can argue for one being better than another, or it doesn’t matter and you just pick one and move on, hopefully without leaving a mess.
A comment describing intention helps a lot if it can be better described in plain writing, this is precisely the kind of thing comments are for.
Thanks a lot! Also one more thing. When I have many functions. I have a hard time naming my variables. I don’t know if this is right, but I always give my variables descriptive names. For example number_of_balls. But when I have many functions that uses the same information I have to rename (to differentiate it and also I thought it is bad style to use the same local variable names in different functions) it like: num_balls or ball_number, total_number_ball, etc. Is that the right way to name variables or should I just use variable names like I, j, k (or is that only for loops)?
i, j, k should only be used if it’s a dumb variable just used for counting with no real meaning, likely meaning index or iteration
Yes, name variables after what the values they refer to represent. (Which means plural for lists and such)
If a function is self-contained then you don’t need to worry about what names other functions might use, but you might want consistent naming if there are concepts shared throughout the program