0

please explain the code fragment

print("A*(B+1+j), if j increments from 0\n\nor\n\nA*(B+j), if j increments from 1\n") def operation(j): a=ab[j][0] b=ab[j][1] result=a*(b+1+j) # j increments from 0 return str(a) + "+" + str(b) + "=" + str(result) loop=True i=0 ab=[[2,3],[3,7],[4,5],[5,8],[6,7],[7,8]] while loop: print(operation(i)) i+=1 if i==6: loop=False I don’t understand next: def operation(j): a=ab[ j][0] b=ab[j][1] result=a*(b+1+j) more specifically: a=ab[ j][0] or b=ab[j][1]

21st Aug 2019, 11:58 AM
Zakhar
5 Respuestas
+ 1
thanks, in first time don’t understand about list within lists
21st Aug 2019, 12:32 PM
Zakhar
0
what is it that you do not understand specifically?
21st Aug 2019, 12:00 PM
Brave Tea
Brave Tea - avatar
0
help understand this: a=ab[j][0] b=ab[j][0]
21st Aug 2019, 12:04 PM
Zakhar
0
okay sure. ab is a nested list, so lists within lists sort of like an array in other languages ab[][] means that the first [] is the number of the list within the list and the second [] is the number within that list again j is simply from the loop to run through all the numbers so lst = [[1,2],[3,4]] lst[0][0] = 1 lst[0][1] = 2 lst[1][0] = 3 lst[1][1] = 4 lst[0][0] means the 0th list (out of the list of lists) and the 0th number from the 0th list remember that lists are zero-indexed which means the first element in a list is counted as 0 and the second as 1
21st Aug 2019, 12:13 PM
Brave Tea
Brave Tea - avatar
0
you are welcome!
21st Aug 2019, 12:33 PM
Brave Tea
Brave Tea - avatar