Computer Science, asked by Anonymous, 5 months ago

L=[]
LI=[]
L2=[ ]
for i in range(6,10):
L.append(i)
for i in range(10,4-2):
L1.append(i)​

Answers

Answered by Equestriadash
10

Given code:

L = []

L1 = []

L2 = []

for i in range(6, 10):    

    L.append(i)

for i in range(10, 4-2):    

    L1.append(i)

print(l)

print(l1)

Output:

[6, 7, 8, 9]

[]

Explanation:

L = []

  • #declaring a list                  

L1 = []

  • #declaring a list                  

L2 = []  

  • #declaring a list              

for i in range(6, 10):

  • #a loop starts, with range values 6 - 9

         L.append(i)

  • #for every value that 'i' takes from the range, it gets added to the first list          

for i in range(10, 4-2):

  • #another loop starts, with range values 10 - 1    

        L1.append(i)

  • #for every value that 'i' takes from the range, it gets added to the second list

print(l)

  • #prints the first list

print(l1)

  • #prints the second list

In L, we have [6, 7, 8, 9]. This is because, from the range (6, 10), the values are 6, 7, 8 and 9. All these values were added to the first list.

In L, we have an empty list. This is because the range given for the loop was (10, 4 - 2), which is (10, 2), which is impossible. You cannot traverse from a larger number to a smaller number. Hence there was no action done to the second list.

Similar questions