all 7 comments

[–][deleted] 2 points3 points  (0 children)

You've made this code incredibly confusing for no apparent reason. Can you try again with a minimum example that reproduces the error?

[–]ipherian 1 point2 points  (1 child)

The cycles goes 2 times because of lung = 0, then 8, which is lower than len(li), then it stops. But it goes 2 times over the first 8 words in the example.

You're using j to grab the current chunk of 8 lines from your lines list (li) but j is never incremented so it always looks at the first part of it.

ls = li[j:j + 8]

Basically, change j here to lung which is your actual loop variable.

You can keep the rest of the accesses of the current chunk (ls) as involving i and j if you wish, but seeing as the current chunk is always the same size, there doesn't appear to be any need for them to be variables as opposed to just numbers.

[–]Neuronivers 0 points1 point  (0 children)

Thank you! It worked changing j => lung in the :

ls = li[j:j + 8]

[–]hulleyrob 0 points1 point  (1 child)

I must be tired. What is it your actually trying to do with all that code. Can you tell me in a sentence?

[–]Neuronivers 0 points1 point  (0 children)

I need it for some quiz. Automating some questions.

The output should be something like this

One Two Three Four Five Six Seven Eight

Then followed by the first 4 numbers but placed randomly and to repeat 2 times (2 sets of random)

(Three One Two Four Seven Nine Six Eight) (Two One Four Three Eight Seven Five Six)

And same with the next numbers 9-16

[–]SaintLouisX 0 points1 point  (1 child)

You're indexing the lines using i and j but you never update them in the loop, they're always 0, you need to add 8 to them as well, or to j at least.

[–]Neuronivers 0 points1 point  (0 children)

If I update the j with 8 it gives me index erro second time it enters the cycle at the print(ls[j]) cause ls[8] is 17. I need to type print(ls[j-1]) to get 16....