+ 1

Write a function to accept a list and swap the number that is divisible by 5 to the next number ..

27th Apr 2021, 2:44 PM
Santhos raj
Santhos raj - avatar
6 Answers
+ 4
Hello UMARANI TIRUKANNAN . Did you try to solve yourself?
27th Apr 2021, 2:47 PM
RKK
RKK - avatar
+ 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)
27th Apr 2021, 3:09 PM
RKK
RKK - avatar
+ 3
Can you post your code here, if possible? Also can you give us an example on how the code should work?
27th Apr 2021, 2:50 PM
RKK
RKK - avatar
+ 1
Yes Stardirt I tried but the first element moves to the last position.
27th Apr 2021, 2:49 PM
Santhos raj
Santhos raj - avatar
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
27th Apr 2021, 2:54 PM
Santhos raj
Santhos raj - avatar
0
Stardust thanks a lot I left that -1 after parenthesis. Can you do it with for loop please.
28th Apr 2021, 10:55 AM
Santhos raj
Santhos raj - avatar