Computer Science, asked by wick77133, 7 months ago


How to solve this?
Write a function which will take 2 arguments. They are:

Sentence

position

Your first task is to take these arguments as user input and pass these values to the function parameters.

Your second task is to implement the function and remove the characters at the index number which is divisible by the position (Avoid the index number 0 as it will always be divisible by the position, so no need to remove the index 0 character). Finally, add the removed characters at the end of the new string.

Return the value and then finally, print the new string at the function call.

Input:
"I love programming."
3
Function call:
function_name("I love programming.", 3)
Output:
I lveprgrmmngo oai.​

Answers

Answered by RitiRajJaiswal
1

Explanation:

How to solve this?

Write a function which will take 2 arguments. They are:

Sentence

position

Your first task is to take these arguments as user input and pass these values to the function parameters.

Your second task is to implement the function and remove the characters at the index number which is divisible by the position (Avoid the index number 0 as it will always be divisible by the position, so no need to remove the index 0 character). Finally, add the removed characters at the end of the new string.

Return the value and then finally, print the new string at the function call.

Input:

"I love programming."

3

Function call:

function_name("I love programming.", 3)

Output:

I lveprgrmmngo oai.

Answered by shahrier2k
3

Answer: A lot of way you can do it but here is a simple one.

def n_func(sen, pos):

   re_str = ""

   n_sen = ""  

   for i in range(1, len(sen)):

       if i % pos == 0:

           re_str = re_str + sen[i]

       else:

           n_sen = n_sen + sen[i]  

   return  sen[0] + n_sen + re_str

sentence = str(input())

position = int(input())

print(n_func(sentence, position))

Explanation:

Similar questions