There is a list s and two variables m and n:
s = [3, 'abc', '123', 'def', '456', 'ghi', '789']
s[0] is type int. It represents the number of times an iteration should occur to assign the following values to m and n.
Ex:
This list of s should be iterated 3 times as denoted by s[0]. Each iteration should assign a new value from s to m and n.
First iteration, m and n should be assigned
m = 'abc'
n = '123'
Second iteration,
m = 'def'
n = '123'`
third iteration,
m = 'ghi'
n = '789'
What I have tried so far -
s = [3, 'abc', '123', 'def', '456', 'ghi', '789']
count = 0
i = 0
j = 2
while count < s[0]:
m = s[i+1]
n = s[j+1]
print(m)
print(n)
count += 1
i += 1
j += 1
My ouput is
abc
def
123
456
def
ghi
instead of
abc
123
def
456
ghi
789
Please help me to build the needed logic to get through this.
n=456? Regardless, Just focus on one variable for a second, saym. Can you write/speak out loud what indexmuses in each iteration? Once you do that, look at your variables being incremented.i += 1? Do you see the problem?