Q. A list Num contains the following elements:
3, 25, 13, 6, 35, 8, 14, 45
Write a function to swap the content with the next value divisible by 5 so that the resultant list will look like:
25, 3, 13, 35, 6, 8, 45, 14
Answer =
num=[3, 25, 13, 6, 35, 8, 14, 45] for i in range(len(num) -1): if num[i+1] % 5 == 0 : num[i],num[i+1]=num[i+1],num[i] print(num)
Output :-
[25, 3, 13, 35, 6, 8, 45, 14]
>>>
output
ReplyDeletenice
DeleteThankyou
ReplyDeleteWelcome : )
DeleteThanks buddy🙂
ReplyDeletethank u
ReplyDeleteit's asked to write as function in question
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )