l = [3,4,5,2, 4] for i in l: for j in range(len(l) - i): if i == l[j]: print(i) else:…
Jump to turn (8)
- 1l = [3,4,5,2, 4] for i in l: for j in range(len(l) - i): if i == l[j]: print(i)
- 2l = [3,4,5,2, 4] for i in l: for j in range(len(l) - i): if i == l[j+1]: print(i
- 3l = [3,4,5,2, 4] for i in l: for j in range(len(l) - i): if i == l[j]: print(i)
- 4printed 4,5,4
- 5int[] array1 = {2, 6, 8, 10}; for(int i = 0; i < array1.Length; i++) { Console.W
- 6no i havnet assigned anything like that
- 7mono /tmp/nPwoM0Qhhq.exe 26 8 10
- 8// Online C# Editor for free // Write, Edit and Run your C# code using C# Online
- User
l = [3,4,5,2, 4]
for i in l: for j in range(len(l) - i): if i == l[j]: print(i) else: continue
- Assistant
There are some issues with the given code.
Firstly, in the inner loop, the range should go from
j+1tolen(l), as you want to compareiwith the elements afterl[j].Secondly, the use of
continueis not necessary here, as the inner loop will naturally continue to the next iteration. So, you can remove theelsestatement.Here's the corrected code:
pythonl = [3,4,5,2,4] for i in l: for j in range(len(l) - i): if i == l[j+1]: print(i)This code will compare each element
iwith the elements that come after it in the listl, and if there is a match, it will print the element.