A list Divisibility contains the following elements:
9, 35, 4, 19, 55, 12, 55, 36
Write a program to swap the content with next value divisible by 5 so that the resultant list will look like
9,4, 35, 19, 12, 55, 36, 55
Answer:
Code:
Divisibility = [
9
,
35
,
4
,
19
,
55
,
12
,
55
,
36
]
n = len(Divisibility)
i =
0
while i<n:
if Divisibility[i]%
5
==
0
:
temp=Divisibility[i]
Divisibility[i]=Divisibility[i+
1
]
Divisibility[i+
1
]=temp
i = i +
2
else:
i = i +
1
print(Divisibility)