+ 1
Write a function to accept a list and swap the number that is divisible by 5 to the next number ..
6 Antworten
+ 4
Hello UMARANI TIRUKANNAN .
Did you try to solve yourself?
+ 4
l = [1,5,2,10,4,6,35]
i = 0
while i<(len(l)-1)-1:
a = l[i]
if a%5==0:
l[i] = l[i+1]
l[i+1] = a
i+=1
i+=1
print(l)
+ 3
Can you post your code here, if possible?
Also can you give us an example on how the code should work?
+ 1
Yes Stardirt I tried but the first element moves to the last position.
0
Stardirt If the list is given as [1,5,2,10,4,6,35]
The output should be [1,2,5,4,10,6,35] the last element should not change even though it is divisible by 5
0
Stardust thanks a lot I left that -1 after parenthesis. Can you do it with for loop please.